scroll.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. (function(){
  2. var special = jQuery.event.special,
  3. uid1 = 'D' + (+new Date()),
  4. uid2 = 'D' + (+new Date() + 1);
  5. special.scrollstart = {
  6. setup: function() {
  7. var timer,
  8. handler = function(evt) {
  9. var _self = this,
  10. _args = arguments;
  11. if (timer) {
  12. clearTimeout(timer);
  13. } else {
  14. evt.type = 'scrollstart';
  15. jQuery.event.dispatch.apply(_self, _args);
  16. }
  17. timer = setTimeout( function(){
  18. timer = null;
  19. }, special.scrollstop.latency);
  20. };
  21. jQuery(this).bind('scroll', handler).data(uid1, handler);
  22. },
  23. teardown: function(){
  24. jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
  25. }
  26. };
  27. special.scrollstop = {
  28. latency: 300,
  29. setup: function() {
  30. var timer,
  31. handler = function(evt) {
  32. var _self = this,
  33. _args = arguments;
  34. if (timer) {
  35. clearTimeout(timer);
  36. }
  37. timer = setTimeout( function(){
  38. timer = null;
  39. evt.type = 'scrollstop';
  40. jQuery.event.dispatch.apply(_self, _args);
  41. }, special.scrollstop.latency);
  42. };
  43. jQuery(this).bind('scroll', handler).data(uid2, handler);
  44. },
  45. teardown: function() {
  46. jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
  47. }
  48. };
  49. })();