Skip to content

Instantly share code, notes, and snippets.

@rutger1140
Created January 5, 2012 12:00
Show Gist options
  • Save rutger1140/1564976 to your computer and use it in GitHub Desktop.
Save rutger1140/1564976 to your computer and use it in GitHub Desktop.
Fix position of element when scrollheight is met
// Make position fixed after scrollheight is met
$(window).scroll(function(e){
var scrollTo = 180;
var scrollClass = '#gf_page_steps_3';
$el = $(scrollClass);
position = $el.position();
if ($(this).scrollTop() > scrollTo && $el.css('position') != 'fixed'){
$(scrollClass).css({'position': 'fixed', 'top': '20px'});
} else if ((position.top < scrollTo) && ($el.css('position') != 'relative')){
$(scrollClass).css({'position': 'relative', 'top': '0px'});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment