[英]Sticky Navigation Issue - “position: fixed” Possibly Not Taking Effect
我有一个托管在平台(Zoey Commerce)上的电子商务网站。 在这个网站上,我有一些非常简单的jQuery,它将CSS应用于元素(标题导航)以便在页面顶部进行修复,因此在滚动时会产生粘性导航。
问题是页眉导航元素固定在页面顶部,但没有随浏览器滚动移动,滚动条的position: fixed
正常position: fixed
通常可以position: fixed
。
请在此处查看网站以查看发生的情况:
http://ts367609-container.zoeysite.com/
请在下面查看我的代码:
<script>
var num = 10; //number of pixels before modifying styles
jQuery(window).bind('scroll', function () {
if (jQuery(window).scrollTop() > num) {
jQuery('#global-wrapper-cp-142f9c37e921e052ae02cddde9be836b').addClass('fixed');
} else {
jQuery('#global-wrapper-cp-142f9c37e921e052ae02cddde9be836b').removeClass('fixed');
}
});
</script>
CSS:
#pix-fe .fixed {
position: fixed !important;
z-index: 9999 !important;
margin-top: 0 !important;
}
代码再简单不过了,所以让我想到了电子商务平台正在引起人们的关注position: fixed
为行为不端。 有人能发现我想念的任何东西吗? 非常感谢您查看此内容,感谢您提前提出任何答案。
尝试使用toggleClass
代替if..else
这样的
$window.scroll(function() {
$('#global-wrapper-cp-142f9c37e921e052ae02cddde9be836b').toggleClass('fixed', $(window).scrollTop() > num);
});
希望能帮助到你 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.