Skip to content

Instantly share code, notes, and snippets.

@sumanahmed
Created September 20, 2017 03:19
Show Gist options
  • Save sumanahmed/18eb3e7550c67fbd0dda14f223efdfa5 to your computer and use it in GitHub Desktop.
Save sumanahmed/18eb3e7550c67fbd0dda14f223efdfa5 to your computer and use it in GitHub Desktop.
JS:
var s = $("#sticker");
var pos = s.position();
$(window).scroll(function(){
var windowpos = $(window).scrollTop();
if(windowpos >= pos.top){
s.addClass("stick");
}else{
s.removeClass("stick");
}
});
CSS:
#sticker{
width: 100%;
}
.stick{
position: fixed;
top: 0px;
z-index: 999999999;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment