开发者

Can you preload images in a dojo animation

开发者 https://www.devze.com 2022-12-20 00:34 出处:网络
I have a dojo animation object of about 15 images. I\'m also using dojo.fx.chain to link them all together.

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消