Last active
December 16, 2015 05:59
-
-
Save Schniz/5388123 to your computer and use it in GitHub Desktop.
Prevents mouse scrolling on the whole page, and just scrolls that awesome selected item.
I don't remember where I found this code, but here it is, converted to jQuery's awesome stuff. example $("ul#awesome-but-long-list").mouseScroll();
returns jQuery $(this), for fluent access
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
/** | |
* Prevents mouse scrolling on the whole page, and just scrolls that awesome selected item. | |
* I don't remember where I found this code, but here it is, converted to jQuery's awesome stuff. | |
* | |
* @example $("ul#awesome-but-long-list").mouseScroll(); | |
* @return jQuery $(this), for fluent access | |
*/ | |
$.fn.mouseScroll = function () { | |
return $(this).bind('mousewheel DOMMouseScroll', function (e) { | |
var delta = e.wheelDelta || -e.detail || e.originalEvent.wheelDelta; | |
var scrollDelta = (delta < 0 ? 1 : -1) * 30; | |
// Check if thats an iScroll | |
if ($(this).data('iScroll-Object') instanceof iScroll) { | |
$(this).data('iScroll-Object').scrollTo(0, scrollDelta, 150, true); | |
} else { // Standard DOM | |
this.scrollTop += scrollDelta; | |
} | |
e.preventDefault(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment