Created
August 8, 2017 17:53
-
-
Save a-eid/8c71c350f5ba73574d251ed9c2db422a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var el = document.querySelector(".shopper-top-menu"); | |
var elOriginal = el.offsetTop | |
window.addEventListener("scroll" , function(e){ | |
if( window.scrollY >= el.offsetTop ) { | |
document.body.style.paddingTop = el.offsetHeight; | |
el.style.position = "fixed"; | |
el.classList.add("fixed") | |
el.style.width = "100%"; | |
el.style.top = 0; | |
el.style.left = 0 ; | |
el.style.zIndex = 100; | |
} | |
if(window.scrollY < elOriginal) { | |
document.body.style.paddingTop = 0; | |
el.classList.remove("fixed") | |
el.style.position = "relative"; | |
el.style.width = "100%"; | |
el.style.zIndex = 100; | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment