Created
March 18, 2013 20:43
-
-
Save cherihung/5190636 to your computer and use it in GitHub Desktop.
make an element on page "stick" while rest of page scrolls
This file contains 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
$(document).ready(function () { | |
$(window).scroll(function(e){ | |
$element = $('#element-id'); | |
var init_height = 250; | |
if ($(this).scrollTop() > init_height && $element.css('position') != 'fixed'){ | |
$('#element-id').css({'position': 'fixed', 'top': '0px'}); | |
} else if ($(this).scrollTop() < init_height && $element.css('position') == 'fixed'){ | |
$('#element-id').css({'position': 'relative'}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment