From afef182d5d1b3f678a03626733d85e02d5558629 Mon Sep 17 00:00:00 2001 From: Nicolas Bages Date: Mon, 26 Aug 2013 10:54:29 +0200 Subject: [PATCH 1/5] Limit the frequency of binded mouseweel events. Add to limit the sensitivity of Apple trackpads but affects regular mouse wheels. --- jquery.mousewheel.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/jquery.mousewheel.js b/jquery.mousewheel.js index 9d65c7162..da397970a 100755 --- a/jquery.mousewheel.js +++ b/jquery.mousewheel.js @@ -23,6 +23,9 @@ } }(function ($) { + var _timeout = 0; + var _isPaused = false; + var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll']; var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll']; var lowestDelta, lowestDeltaXY; @@ -56,7 +59,8 @@ }; $.fn.extend({ - mousewheel: function(fn) { + mousewheel: function(fn, time) { + _timeout = time; return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel"); }, @@ -67,6 +71,14 @@ function handler(event) { + + if(_isPaused){ return; } + + if(_timeout > 0){ + _isPaused = true; + setTimeout(function(){ _isPaused = false; }, _timeout); + } + var orgEvent = event || window.event, args = [].slice.call(arguments, 1), delta = 0, From eef18dd00f2353d7cad05137c07f42fec032a8cc Mon Sep 17 00:00:00 2001 From: Nicolas Bages Date: Mon, 26 Aug 2013 10:59:45 +0200 Subject: [PATCH 2/5] Update documentation by adding how to use modify the frequency of triggered events --- README.markdown | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.markdown b/README.markdown index 66086b43a..afa896e2f 100644 --- a/README.markdown +++ b/README.markdown @@ -20,6 +20,13 @@ $('#my_elem').mousewheel(function(event, delta, deltaX, deltaY) { console.log(delta, deltaX, deltaY); }); ``` +# Limit frequency + +You must use .mouseweel() method instead of .on() method to add the delay parameter. It will limit the frequency of triggered events. + + // Exemple : 250 milliseconds = 4 times / second + $('selector').mousewheel(fn, 250); + ## See it in action [See the tests on Github](http://brandonaaron.github.com/jquery-mousewheel/test). From 369cda6b5e876efcf8e09f2922da0f92616c2851 Mon Sep 17 00:00:00 2001 From: Nicolas Bages Date: Mon, 26 Aug 2013 11:00:36 +0200 Subject: [PATCH 3/5] fix doc style --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index afa896e2f..758fab0a1 100644 --- a/README.markdown +++ b/README.markdown @@ -20,7 +20,7 @@ $('#my_elem').mousewheel(function(event, delta, deltaX, deltaY) { console.log(delta, deltaX, deltaY); }); ``` -# Limit frequency +## Limit frequency You must use .mouseweel() method instead of .on() method to add the delay parameter. It will limit the frequency of triggered events. From a1bb337cca2f04bf52c277071633747ec62850b0 Mon Sep 17 00:00:00 2001 From: Nicolas Bages Date: Mon, 26 Aug 2013 11:01:27 +0200 Subject: [PATCH 4/5] fix doc style --- README.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 758fab0a1..28cfede88 100644 --- a/README.markdown +++ b/README.markdown @@ -24,9 +24,10 @@ $('#my_elem').mousewheel(function(event, delta, deltaX, deltaY) { You must use .mouseweel() method instead of .on() method to add the delay parameter. It will limit the frequency of triggered events. +```js // Exemple : 250 milliseconds = 4 times / second $('selector').mousewheel(fn, 250); - +``` ## See it in action [See the tests on Github](http://brandonaaron.github.com/jquery-mousewheel/test). From 5658535d37dfb353657724671c7f6778b6a65915 Mon Sep 17 00:00:00 2001 From: Nicolas Bages Date: Mon, 26 Aug 2013 11:03:09 +0200 Subject: [PATCH 5/5] fix doc style --- README.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 28cfede88..470e53c10 100644 --- a/README.markdown +++ b/README.markdown @@ -26,7 +26,9 @@ You must use .mouseweel() method instead of .on() method to add the delay parame ```js // Exemple : 250 milliseconds = 4 times / second - $('selector').mousewheel(fn, 250); + $('selector').mousewheel(function(event, delta, deltaX, deltaY) { + console.log(delta, deltaX, deltaY); + }, 250); ``` ## See it in action