Skip to content

Instantly share code, notes, and snippets.

@zumwalt
Created July 19, 2013 20:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zumwalt/6042072 to your computer and use it in GitHub Desktop.
Save zumwalt/6042072 to your computer and use it in GitHub Desktop.
Keeps the window/body from scrolling while you're focused on a fixed/absolute element that also scrolls.
$('#element').bind('mousewheel DOMMouseScroll', function(e) {
var scrollTo = null;
if (e.type == 'mousewheel') {
scrollTo = (e.originalEvent.wheelDelta * -1);
}
else if (e.type == 'DOMMouseScroll') {
scrollTo = 40 * e.originalEvent.detail;
}
if (scrollTo) {
e.preventDefault();
$(this).scrollTop(scrollTo + $(this).scrollTop());
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment