Skip to content

Instantly share code, notes, and snippets.

@elmahdim
Last active August 9, 2016 08:51
Show Gist options
  • Save elmahdim/8a7c3424c0900ecb64a5 to your computer and use it in GitHub Desktop.
Save elmahdim/8a7c3424c0900ecb64a5 to your computer and use it in GitHub Desktop.
Freeze element once reached to the scrollbar offset
var offset = $("SELECTOR").offset();
if($('SELECTOR').get(0)) {
$(window).scroll(function() {
if ( $('body').scrollTop() > offset.top){
$('SELECTOR').addClass('is-fixed');
} else {
$('SELECTOR').removeClass('is-fixed');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment