Skip to content

Instantly share code, notes, and snippets.

@bryanwillis
Forked from guillermorangel/sticky-scroll
Created August 12, 2013 18:07
Show Gist options
  • Save bryanwillis/6213386 to your computer and use it in GitHub Desktop.
Save bryanwillis/6213386 to your computer and use it in GitHub Desktop.
$(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