使导航栏粘

Mar*_*rra 2 html css jquery sticky

伙计们,

我的网站上有一个导航栏(http://www.mtscollective.com - 'menu-secondary-wrap'),当用户向下滚动时,我试图让它保持在页面顶部.

我已经测试了几个jQuery示例(例如http://www.hongkiat.com/blog/css-sticky-position/),但它们总是带有自己的CSS,这似乎会干扰我已经使用的内容.

对现有课程来说,最简单/最好的方法是什么?

谢谢!马里奥

Nik*_*nov 5

使用这样的东西(你可以在浏览器控制台F12中查看)

jQuery(window).scroll(function() {
  if (jQuery(this).scrollTop() > 220) {
    jQuery(".menu-secondary-wrap").css({"position": "fixed", "top": 0, "width": "950px"});
  } else {
    jQuery(".menu-secondary-wrap").removeAttr("style");
  }
});
Run Code Online (Sandbox Code Playgroud)

工作完全没问题