Created
July 31, 2013 20:42
-
-
Save guillermorangel/6125965 to your computer and use it in GitHub Desktop.
sticky content after scroll
This file contains hidden or 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
$(function(){ // document ready | |
if (!!$('.sticky').offset()) { // make sure ".sticky" element exists | |
var stickyTop = $('.sticky').offset().top; // returns number | |
$(window).scroll(function(){ // scroll event | |
var windowTop = $(window).scrollTop(); // returns number | |
if (stickyTop < windowTop){ | |
$('.sticky').css({ position: 'fixed', top: 0 }); | |
} | |
else { | |
$('.sticky').css('position','static'); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment