I know this is learning but why not look at Asset.images in Asset.js
from more here for inspiration? It's a great implementation.
--
Dimitar Christoff
"JavaScript is to JAVA what hamster is to ham"
Personal blog: http://fragged.org/ - Twitter: @D_mitar
It can be simple-ish:
basically, delay is a function decorator, you tell it to run the method
fade from whatever:
var pre = $("preloader");
// from host obj a fade.
Element.fade(pre, [0,1]);
// delayed from host obj - first arg is element, second is for fade
Element.fade.delay(1000, null, [pre, [0,1]]);
// from prototype, bind, simpler - bind to object, pass arg
Element.prototype.fade.delay(2000, pre, [0,1]);
// kind of the same as above
pre.fade.delay(3000, pre, [0,1]);
the jquery one will basically make a function out of $(this).fadeOut()
and run it after 500ms, so it's kind of written backwards but the end
result is the same as your initial mootools one.
http://jsfiddle.net/dimitar/4YsUV/9/
One thing I'd consider is the undocumented overload option to tween
instance through fade - i.e. .fade(1, 0) ensures a start and env value
for the tween.
Anyway.
var pre = $("preloader");
pre.fade.delay(5000, pre, [1, 0]); - works
Yes, why not - mootools is what you make out of it - though your method
is not chainable as is - it defers the action and returns nothing. add
return this;
even so, the return this can have unexpected behaviours if you destroy
the element before it runs.
eg. $("foo").fadeout(5000).destroy(); -> 5 second later, you have an
exception. this sort of pattern does not allow you to check if the
element still exists when it runs nor does it degrade gracefully when it
does not nor does it cater for management of timers - what happens when
you .fadeout(3000).fadeout(3010)?
will create 2 separate functions with no respect for tweening going on
at the moment.
if none of that is a concern, you don't need to go to dealing with
element.tween directly and manage it. else, you may be better off doing
that instead.
--
Dimitar Christoff
"JavaScript is to JAVA what hamster is to ham"
http://fragged.org/ | @D_mitar | https://github.com/DimitarChristoff