试图让我的引导程序navabar背景淡出滚动在我的wordpress主题
Trying to have my bootstrap navabar background fade in on scroll in my wordpress theme
到目前为止,我有以下代码:
CSS
.navbar {
background-color:rgba(51, 49, 50, 1);transition: background-color 2s ease 0s;
}
.navbar.hide {
background-color:rgba(51, 49, 50, 0);transition: background-color 2s ease 0s;
}
Javascript
$(window).scroll(function() {
if($(this).scrollTop() > 300) {
$('.navbar').addClass('hide');
} else {
$('.navbar').removeClass('hide');
}
});
这在我的函数中。hp:
function wpbootstrap_scripts_with_jquery()
{
// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . '/bootstrap/js/bootstrap.js', array( 'jquery' ) );
wp_register_script( 'scrollfade', get_template_directory_uri() . '/js/scrollfade.js');
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'custom-script' );
wp_enqueue_script( 'scrollfade' );
}
add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );
add_action( 'wp_enqueue_scripts', 'wpbootstrap_scrollfade' );
我可以看到脚本加载在页面源代码的头部分,但还是出了什么问题?
通过将其添加到我的js文件中来解决:
(function($) {
$(document).ready(function(){
$(window).scroll(function(){
if ($(this).scrollTop() > 300) {
$('.navbar').addClass('hide');
} else {
$('.navbar').removeClass('hide');
}
});
});
})(jQuery);
相关文章:
- 我希望只有在我滚动页面后才能显示我的返回页首图标
- 为什么不'我的窗口滚动事件根本没有启动.其他答案没有解决问题
- 更新Wordpress和我的平滑滚动停止工作
- 试图让我的引导程序navabar背景淡出滚动在我的wordpress主题
- 使用我的基于标签的平滑滚动脚本而不带“a”的解决方案
- 如何防止我的引导可折叠框滚动页面
- 为什么我的修复菜单在滚动时无法顺利运行
- 我想滚动放大和缩小一个图像,但也有针在该图像上保持正确的位置.jQuery
- 如何将图像放入我的滚动文本js中
- 打开对话框正在更改我的滚动顶部位置
- 为什么我的滚动条与我想要的相反
- Fancybox update()函数重置我的滚动
- 为什么不是'我的滚动图像无法正常工作
- 为什么不是'我的滚动太流畅了
- 为什么引导模式会在关闭模式并锚定到页面后删除我的滚动条
- 我如何才能将我的滚动脚本变成一个单独的功能
- 我的滚动加载没有'我不能在IE 8上工作
- 我的滚动不工作在三星安卓手机,但在所有的浏览器和设备工作良好
- 如何知道多少我的滚动移动使用纯Js或jquery
- 为什么我的滚动eventListener没有触发