The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Christmas story with Santa sleigh progress bar Reply To: Christmas story with Santa sleigh progress bar


One day is full of great discoveries, the next can be hours of struggle over something basic. But it’s worth it.

Edit – is what I said before posting code I thought worked well but was majorly glitched.


Second edit – I’ll just include the demo. Looks like I was misinterpreting the logged feedback…

Throtttle/debounce with a twist

Hard to explain what it does. But is fires the debounced event always the exact amount of delay after the last time the inner function was executed. As opposed to firing it after the final user action (which may not always lead to an inner execution).

function restrain(delay, callback) {

var executed = 0, debounce,
throttle = function() {

    var elapsed = Math.min(delay,,
    remain = delay-elapsed;

    function runIt() {
    if (!remain) executed =;
    callback.apply(this, arguments);

    debounce && clearTimeout(debounce);
    elapsed == delay && runIt();
    if (remain) debounce = setTimeout(runIt, remain);

return throttle;

Such a little function, still a lot to try and wrap my head around what happens for all possible cases exactly. Lol.