Last active
August 9, 2016 08:51
-
-
Save elmahdim/8a7c3424c0900ecb64a5 to your computer and use it in GitHub Desktop.
Freeze element once reached to the scrollbar offset
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 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