简体   繁体   English

粘性导航菜单

[英]Sticky Navigation Menu

Here is the link: JSFIDDLE 这是链接: JSFIDDLE

$('.main-menu').addClass('fixed');

How come the fixed element is flickering whenever the fixed class is added? 为什么固定元素在添加固定类时会闪烁?

You're constantly removing and re-adding the fixed CSS attribute because everytime you scroll, the top offset changes. 您不断删除并重新添加fixed CSS属性,因为每次滚动时,顶部偏移都会发生变化。 What you want to do is store it in a variable on load, then compare against that variable. 您要做的是在加载时将其存储在变量中,然后与该变量进行比较。 JSFiddle: http://jsfiddle.net/j44xdv3m/6/ JSFiddle: http//jsfiddle.net/j44xdv3m/6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM