Skip to content

Instantly share code, notes, and snippets.

@andreystarkov
Created February 14, 2014 11:09
Show Gist options
  • Save andreystarkov/8999365 to your computer and use it in GitHub Desktop.
Save andreystarkov/8999365 to your computer and use it in GitHub Desktop.
scrollSomething
function scrollSomething($sidebar, $window, topPadding){
var offset = $sidebar.offset();
$window.scroll(function() {
if ($window.scrollTop() > offset.top) {
$sidebar.stop().animate({
marginTop: $window.scrollTop() - offset.top + topPadding
}, {duration: 700, easing: 'easeOutCubic'});
} else {
$sidebar.stop().animate({
marginTop: 0
}, {duration: 700, easing: 'easeIn'});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment