tags:

views:

214

answers:

2

I have a dojo animation object of about 15 images. I'm also using dojo.fx.chain to link them all together.

Right before I create all my dojo.fadeIn's and dojo.fadeOut's I added in some basic javascript to preload each image.

My question is: Am I doing this the hard way or is there some function/attr I can set in the animation object to do this?

A: 

I do not think there is a predefined method in dojo to preload these images for your animation.

I guess you are listening image.onload and image.onerror events to preload images, it is a common method. If you feel it is too difficult and hard to control, you can try a simple clean css way that is to put an invisible div into your page and set background images with these animation images. When the page load, the images are automatically loaded.

virsir
A: 

dojo Animations are not specifically geared around images, they work on an abstract level and may operate on DOM nodes. So, there's no built-in support for IMG nodes specifically.

There is dojox.image.preload (http://api.dojotoolkit.org/jsdoc/HEAD/dojox.image.preload) which will do the work virsir suggested of loading images into an offscreen div, but it does not (currently) arrange an onLoad event hook for you to detect when they're loaded and thus play your animation.

I imagine you could use preload()'s return value and use it to hook into onLoad, but that's an exercise for the reader. Have a look at the source code, dojox/image/_base.js.

Neek