Created
July 19, 2013 20:22
-
-
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.
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
$('#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