Home › Forums › Other › Christmas story with Santa sleigh progress bar › Reply To: Christmas story with Santa sleigh progress bar
December 5, 2016 at 12:47 pm
#248680
Shikkediel
Participant
I guess he’ll sleep a bit less comfortably but as least he won’t catch a cold with his bottom all exposed. Lol.
I find the JS quite interesting, especially the throttle function because it is something I’ve been recently fiddling with myself as well.
(function(window, undefined) {
window.vial = {};
vial.restrain = function(delay, callback) {
var loop, executed = 0;
function moduleWrap() {
var elapsed = Date.now()-executed;
function runIt() {
executed = Date.now();
callback.apply(this, arguments);
}
if (elapsed > delay) runIt();
loop && clearTimeout(loop);
loop = setTimeout(function() {
callback.apply(this, arguments);
}, delay+100);
}
return moduleWrap;
}
})(this);
Example:
$(window).resize(vial.restrain(100, someFunction));
Plus I’ve been creating a small library lately, a single window object called vial
where all other functions and info is deposited. This has the advantage that the methods can be used outside an anonymous function.
Admittedly the basics were extracted from Ben Alman’s plugin. I would’ve never come up with a “forwarded” function using apply
myself.
:-)