Skip to content

Instantly share code, notes, and snippets.

@accessomnath
Created February 7, 2018 14:11
Show Gist options
  • Save accessomnath/8e68128f6147f90c077eaa4219ceff95 to your computer and use it in GitHub Desktop.
Save accessomnath/8e68128f6147f90c077eaa4219ceff95 to your computer and use it in GitHub Desktop.
When you are doing some crazy thing to your menus
// 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