Created
February 7, 2018 14:11
-
-
Save accessomnath/8e68128f6147f90c077eaa4219ceff95 to your computer and use it in GitHub Desktop.
When you are doing some crazy thing to your menus
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
// lock scroll position, but retain settings for later | |
var scrollPosition = [ | |
self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft, | |
self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop | |
]; | |
var html = jQuery('html'); // it would make more sense to apply this to body, but IE7 won't have that | |
html.data('scroll-position', scrollPosition); | |
html.data('previous-overflow', html.css('overflow')); | |
html.css('overflow', 'hidden'); | |
window.scrollTo(scrollPosition[0], scrollPosition[1]); | |
// un-lock scroll position | |
var html = jQuery('html'); | |
var scrollPosition = html.data('scroll-position'); | |
html.css('overflow', html.data('previous-overflow')); | |
window.scrollTo(scrollPosition[0], scrollPosition[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment