Skip to content

Instantly share code, notes, and snippets.

@a-eid
Created August 8, 2017 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-eid/8c71c350f5ba73574d251ed9c2db422a to your computer and use it in GitHub Desktop.
Save a-eid/8c71c350f5ba73574d251ed9c2db422a to your computer and use it in GitHub Desktop.
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