Skip to content

Instantly share code, notes, and snippets.

@CoolS2
Created August 9, 2016 10:33
Show Gist options
  • Select an option

  • Save CoolS2/5de2376134ef719a0cba36debab55205 to your computer and use it in GitHub Desktop.

Select an option

Save CoolS2/5de2376134ef719a0cba36debab55205 to your computer and use it in GitHub Desktop.
$.fn.followTo = function (pos) {
var $this = this,
$window = $(window);
$window.scroll(function (e) {
if ($window.scrollTop() > pos) {
$this.css({
position: 'absolute',
top: pos
});
} else {
$this.css({
position: 'fixed',
top: 0
});
}
});
};
$('#yourDiv').followTo(250);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment