Created
August 12, 2018 06:31
-
-
Save rintoug/8756754427ab5894e98c060ef741037f to your computer and use it in GitHub Desktop.
How to fix div when browser scrolls?
This file contains hidden or 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
jQuery(function($) { | |
function fixDiv() { | |
var $cache = $('#getFixed'); | |
if ($(window).scrollTop() > 100) | |
$cache.css({ | |
'position': 'fixed', | |
'top': '10px' | |
}); | |
else | |
$cache.css({ | |
'position': 'relative', | |
'top': 'auto' | |
}); | |
} | |
$(window).scroll(fixDiv); //Just capture the scroll event and execute the function | |
fixDiv(); // call on load of the page | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment