![](/img/trans.png)
[英]jQuery: change text color of a fixed top navbar at the scrolling of the page
[英]Navbar becomes fixed on scrolling in jquery 2.2.4 but not in jquery 3.1.1
我正在尝试使用预定义的主题在jekyll
创建一个网站。 但是,在我的bower.json
, jquery
版本被提到为"^3.1.0"
,导航栏没有固定,并且随着向下滚动页面而向上移动,而在原始源代码中,使用的版本是2.2.3
,因此当我将bower.json
jquery
版本bower.json
为"^2.2.3"
,它起作用了! 这是滚动的javascript代码。 为什么会这样呢? 另外,是否建议将网站中的依赖项版本更新为最新版本,如我应该将jquery
更新为最新版本一样?
// Window Scroll
var windowScroll = function () {
$(window).scroll(function () {
var scrollPos = $(this).scrollTop();
var system ={win : false,mac : false,xll : false};
//¼ì²âƽ̨
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
//ÅжÏƽ̨ÀàÐÍ
if(system.win||system.mac||system.xll){
if ($(window).scrollTop() > 70)
{
$('.site-header').addClass('site-header-nav-scrolled');
} else {
$('.site-header').removeClass('site-header-nav-scrolled');
}
}else{
//Èç¹ûÊÇÊÖ»úÔò½«¶¥À¸ÒƳý½çÃæ
if ($(window).scrollTop() > 40)
{
$('.site-header').addClass('site-header-nav-scrolled-ph');
} else {
$('.site-header').removeClass('site-header-nav-scrolled-ph');
}
}
});
};
$( document ).ready(function() {
windowScroll();
});
在3.1.1 https://jsfiddle.net/br3t/pujfta96/上对我来说工作正常。
另外,您还创建了scrollPos
,但是在if-else语句中使用$(window).scrollTop()
。
您不会检测每个滚动的system
,只需在windowScroll
设置一次windowScroll
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.