Created
March 3, 2012 01:54
-
-
Save bryanchow/1963544 to your computer and use it in GitHub Desktop.
Custom start and stop scrolling events for jQuery.jScrollPane
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
/*jshint browser:true */ | |
/*global jQuery */ | |
/* | |
jquery.scrollpane-startstop.js | |
Custom start and stop scrolling events for jScrollPane | |
https://gist.github.com/1963544 | |
Usage: | |
$('#scroller').jScrollPane().bind('panescrollstart', function() { | |
console.log('Scrolling started'); | |
}).bind('panescrollstop', function() { | |
console.log('Scrolling stopped'); | |
}); | |
jScrollPane | |
http://jscrollpane.kelvinluck.com/ | |
Insipred by James Padolsey's Special Scroll Events | |
http://james.padolsey.com/javascript/special-scroll-events-for-jquery/ | |
*/ | |
(function($) { | |
var special = $.event.special, | |
uid1 = 'D' + (+new Date()), | |
uid2 = 'D' + (+new Date() + 1), | |
latency = 300; | |
special.panescrollstart = { | |
setup: function() { | |
var timer; | |
var handler = function(evt) { | |
var _self = this, | |
_args = arguments; | |
if (timer) { | |
clearTimeout(timer); | |
} else { | |
evt.type = 'panescrollstart'; | |
$.event.handle.apply(_self, _args); | |
} | |
timer = setTimeout(function() { | |
timer = null; | |
}, latency); | |
}; | |
$(this).bind('jsp-scroll-x', handler).data(uid1, handler); | |
$(this).bind('jsp-scroll-y', handler).data(uid1, handler); | |
}, | |
teardown: function(){ | |
$(this).unbind( 'jsp-scroll-x', $(this).data(uid1) ); | |
$(this).unbind( 'jsp-scroll-y', $(this).data(uid1) ); | |
} | |
}; | |
special.panescrollstop = { | |
setup: function() { | |
var timer; | |
var handler = function(evt) { | |
var _self = this, | |
_args = arguments; | |
if (timer) { | |
clearTimeout(timer); | |
} | |
timer = setTimeout( function(){ | |
timer = null; | |
evt.type = 'panescrollstop'; | |
$.event.handle.apply(_self, _args); | |
}, latency); | |
}; | |
$(this).bind('jsp-scroll-x', handler).data(uid2, handler); | |
$(this).bind('jsp-scroll-y', handler).data(uid2, handler); | |
}, | |
teardown: function() { | |
$(this).unbind( 'jsp-scroll-x', $(this).data(uid2) ); | |
$(this).unbind( 'jsp-scroll-y', $(this).data(uid2) ); | |
} | |
}; | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the latest versions of jQuery plugin does not work. The problem is that "$. Event.handle.apply" is deprecated. I modified the code so "$ (_self). Triggers (evt.type, _args)," and started to work.