Javascript fixed top navigator only after scrolling

Does anyone know what javascript effects are used to create a navigation effect on lesscss.org , where the navbar only fixes on top after scrolling for a specific point. If anyone has actual code examples or links to tutorials, that would be appreciated.

+4
source share
1 answer

this is javascript validation using the window.onscroll event

in the HTML source at the top:

 window.onscroll = function () { if (!docked && (menu.offsetTop - scrollTop() < 0)) { menu.style.top = 0; menu.style.position = 'fixed'; menu.className = 'docked'; docked = true; } else if (docked && scrollTop() <= init) { menu.style.position = 'absolute'; menu.style.top = init + 'px'; menu.className = menu.className.replace('docked', ''); docked = false; } }; 
+6
source

Source: https://habr.com/ru/post/1439266/


All Articles