|
65 | 65 | * End jQuery UI Position |
66 | 66 | **/ |
67 | 67 |
|
| 68 | + /** |
| 69 | + * throttle from: |
| 70 | + * http://remysharp.com/2010/07/21/throttling-function-calls/ |
| 71 | + */ |
| 72 | + function throttle(fn, threshhold, scope) { |
| 73 | + threshhold || (threshhold = 250); |
| 74 | + var last, |
| 75 | + deferTimer; |
| 76 | + return function () { |
| 77 | + var context = scope || this; |
| 78 | + |
| 79 | + var now = +new Date, |
| 80 | + args = arguments; |
| 81 | + if (last && now < last + threshhold) { |
| 82 | + // hold on to it |
| 83 | + clearTimeout(deferTimer); |
| 84 | + deferTimer = setTimeout(function () { |
| 85 | + last = now; |
| 86 | + fn.apply(context, args); |
| 87 | + }, threshhold); |
| 88 | + } else { |
| 89 | + last = now; |
| 90 | + fn.apply(context, args); |
| 91 | + } |
| 92 | + }; |
| 93 | + } |
| 94 | + |
68 | 95 | function trackScrolling( scroller ) { |
69 | 96 |
|
70 | 97 | var _waiter = null; |
71 | 98 |
|
72 | | - scroller.onscroll = function ( e ) { |
73 | | - |
74 | | - if ( !_waiter && !scroller.ignoreScrolling ) { |
| 99 | + scroller.onscroll = throttle( function ( e ) { |
75 | 100 |
|
76 | | - _waiter = setTimeout(function () { |
| 101 | + if ( !scroller.ignoreScrolling ) { |
77 | 102 |
|
78 | | - $.each(scroller.watch, function () { |
| 103 | + $.each(scroller.watch, function () { |
79 | 104 |
|
80 | | - this._checkPositioning( e ); |
| 105 | + this._checkPositioning( e ); |
81 | 106 |
|
82 | | - }); |
83 | | - |
84 | | - _waiter = null; |
85 | | - |
86 | | - }, $.osb.scrollable.CONFIG.throttler); |
| 107 | + }); |
87 | 108 | } |
88 | 109 |
|
89 | | - } |
| 110 | + }, $.osb.scrollable.CONFIG.throttler ); |
90 | 111 |
|
91 | 112 | //console.log( 'Start listening to scrolling' ); |
92 | 113 | scroller.element.on('scroll.scrollable', scroller.onscroll); |
@@ -163,7 +184,7 @@ window.Scrollable = monitor; |
163 | 184 |
|
164 | 185 | $.widget('osb.scrollable', { |
165 | 186 |
|
166 | | - version: "0.1.4", |
| 187 | + version: "0.1.5", |
167 | 188 |
|
168 | 189 | widgetEventPrefix: 'scroll', |
169 | 190 |
|
|
0 commit comments