Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const docQuerySelectorAll =
- selector => Array.from( document.querySelectorAll( selector ) );
- //sticky_nav
- const sticky_navArray = docQuerySelectorAll( ".sticky_nav" )
- const sticky_navArrayStartTopPositions = []
- sticky_navArray.forEach(
- node => sticky_navArrayStartTopPositions.push( node.offsetTop )
- )
- const getStartYPosition = node =>
- sticky_navArrayStartTopPositions[sticky_navArray.indexOf( node )]
- const sticky_nav = () => {
- sticky_navArray.forEach( node => {
- let scrolled = window.pageYOffset || document.documentElement.scrollTop;
- if ( scrolled > getStartYPosition( node ) ) {
- node.style.position = "fixed";
- node.style.top = 0;
- } else {
- node.style.top = null;
- node.style.position = null;
- }
- return null;
- } );
- }
- document.addEventListener( "scroll", () => {
- sticky_nav();
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement