Created
June 12, 2013 01:24
-
-
Save jayde/5762251 to your computer and use it in GitHub Desktop.
Lock body scroll bar while scrolling div
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
// url: http://stackoverflow.com/questions/7600454/how-to-prevent-page-scrolling-when-scrolling-a-div-element | |
// function | |
$.fn.isolatedScroll = function() { | |
this.bind('mousewheel DOMMouseScroll', function (e) { | |
var delta = e.wheelDelta || (e.originalEvent && e.originalEvent.wheelDelta) || -e.detail, | |
bottomOverflow = this.scrollTop + $(this).outerHeight() - this.scrollHeight >= 0, | |
topOverflow = this.scrollTop <= 0; | |
if ((delta < 0 && bottomOverflow) || (delta > 0 && topOverflow)) { | |
e.preventDefault(); | |
} | |
}); | |
return this; | |
}; | |
// call function | |
$('.scrollable').isolatedScroll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment