简体   繁体   English

我如何获得一个滚动页面和导航的导航,当它使用普通的javascript到达顶部导航

[英]how do i get a navigation that scrolls with page and stick when it reaches the top nav with plain javascript

How can make a div elememt move up when a user scrolls and then stay fixed when it reaches the top of the page? 如何在用户滚动时使div elememt向上移动,然后在到达页面顶部时保持固定状态? I already have a fixed bar under which i expect this div to stay. 我已经有一个固定的酒吧,我期望这个div留下来。

What you want is a sticky block. 你想要的是一个粘性块。 There is a (relatively) new CSS feature position: sticky , but unfortunately it works not in all browsers. 有一个(相对)新的CSS功能position: sticky ,但不幸的是它并不适用于所有浏览器。 You can use it in combination with a polyfill 您可以将它与polyfill结合使用

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

相关问题 如何使用 vanilla javascript 判断元素的顶部或底部何时滚动到页面顶部 - How do I tell when the top or bottom of an element scrolls to the top of the page using vanilla javascript 当 javascript int++ 达到选定值时,如何跳转到 Page Top []? - How do I jump to the Page Top [ ] when a javascript int++ reaches a chosen value? 当div到达窗口顶部时,如何使它粘在顶部 - How to make a div stick to top when it reaches the top of the window 当查看器滚动时,如何使网站的导航栏位于顶部? - How do I make the navigation bar of my site stay at the top when the viewer scrolls? 当JQuery到达页首时,JQuery添加文本元素 - JQuery Add Text Element To Nav When It Reaches Top Of Page Javascript:导航栏在向上滚动并到达顶部时消失 - Javascript: Nav bar disappears when scrolling up and reaches the top 如何找到该部分到达顶部并使用纯JavaScript添加类 - How to find the section reaches the top and add a class using plain javascript 当锚点到达视口顶部时,如何触发jQuery? - How do I trigger jQuery when an anchor reaches the top of the viewport? 滚动时我无法使导航栏停留在顶部 - I can't making the navigation bar stick to top when scrolling 滚动到窗口上方时如何将div /导航栏粘贴到窗口顶部 - How to stick a div/navigation bar to the top of the window when scrolled past it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM