Forked from theftprevention/jquery-scrolllock.js
Last active
December 21, 2015 22:49
-
-
Save Flayed/6378253 to your computer and use it in GitHub Desktop.
Locks the mousewheel scrolling functionality to a particular element. This version also handles horizontal scrolling (that is, spinning the mouse wheel while holding the shift key).
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
$.fn.scrollLock = function () { return $(this).on("DOMMouseScroll mousewheel", function (h) { var g = $(this), s = h.shiftKey, f = (s ? this.scrollLeft : this.scrollTop), d = (s ? this.scrollWidth : this.scrollHeight), b = (s ? g.width() : 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) { if (s) { g.scrollLeft(d); } else { g.scrollTop(d); } return c() } else { if (a && i > f) { if (s) { g.scrollLeft(0); } else { 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