Forked from theftprevention/jquery-scrolllock.js
Last active
August 29, 2015 13:56
-
-
Save jonathan-beebe/9252009 to your computer and use it in GitHub Desktop.
A small jQuery extension that disables the propagation of scroll events from the first element in the set of matched elements. Original function by Troy Alford of Stack Overflow. $("#object").scrollLock() enables the lock, and .scrollRelease() disables it. In response to this SO question: http://stackoverflow.com/a/16324762/123781
This file contains 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
$.fn.scrollLock = function () { | |
return $(this).on("DOMMouseScroll mousewheel", function (h) { | |
var g = $(this), | |
f = this.scrollTop, | |
d = this.scrollHeight, | |
b = g.height(), | |
i = h.originalEvent.wheelDelta, | |
a = i > 0, | |
c = function () { | |
h.stopPropagation(); | |
h.preventDefault(); | |
h.returnValue = false; | |
return false | |
}; | |
if (!a && -i > d - b - f) { | |
g.scrollTop(d); | |
return c() | |
} else { | |
if (a && i > f) { | |
g.scrollTop(0); | |
return c() | |
} | |
} | |
}) | |
}; | |
$.fn.scrollRelease = function () { | |
return $(this).off("DOMMouseScroll mousewheel") | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment