Skip to content

Instantly share code, notes, and snippets.

@a-eid a-eid/sticky.js
Created Aug 8, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.