我有一个eCommerce网站,这是在一个平台(佐伊商业)托管。在这个网站上,我有一些非常简单的jQuery,它将应用CSS到一个元素(标题导航),以修复它在页面的顶部,因此创建一个粘性导航滚动。
问题是标题导航元素固定在页面的顶部,但它没有随浏览器滚动一起移动,这并没有像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;
}
代码再简单不过了,所以我认为是eCommerce平台导致了position: fixed
的不正常行为。有没有人能进一步发现我遗漏的东西?非常感谢你看这篇文章,我很感谢你提前给我答复。
发布于 2016-07-09 01:53:07
尝试使用toggleClass
而不是if..else
,如下所示
$window.scroll(function() {
$('#global-wrapper-cp-142f9c37e921e052ae02cddde9be836b').toggleClass('fixed', $(window).scrollTop() > num);
});
希望它能有所帮助:)
https://stackoverflow.com/questions/38272602
复制相似问题