mootools/mootools-more — Issue #1048: Pseudo: throttle ignores events in last timeout
Author: RiZKiT
Created: 2011-10-13 11:48:01+00:00
State: open

I use scroll:throttle to calculate the position of an element. The problem is that the scroll events in the last timeout are ignored. I don't know if that is the planned functionality or a bug.

Example:
* I use scroll:throttle(1000) and a scroll occurs which takes 1.9 seconds.
* As a result the associated function is executed after 0 seconds and after 1 second. But the scroll isn't finished yet, 0.9 seconds later it's finished, but the calculation function will not be executed, because scroll events in the last timeout are ignored.

I know the timeout (1000 miliseconds) is quite high, but it's just an example. Even if I set the timeout to 100 miliseconds, the calculated position would be wrong. And calculation on every scroll event isn't an option.

Here is my suggestion which solves the problem "above". Now the function will be executed after 1 second and after 2 seconds.

```javascript
DOMEvent.definePseudo('throttle', function(split, fn, args){
if (!fn._throttled){
fn._throttled = (function(){
fn._throttled = false;
fn.apply(this, args);
}).delay(split.value || 250)
}
});
```