使用dojo实现动画效果
dojo提供了一些动画辅助层,在Base dojo(dojo.js)基础上,形成逐级添加的一个模块系统,dojo中的所有动画都
是围绕一个单独的类:dojo._Animation
开始了解dojo._Animation
就象开始提到的那样,dojo._Animation是所有dojo动画类的基类,它提代了一些简单的方法可以很好的控制你的动画,比如播放,暂停,停止,和跳到指定位置,所以动画中最简单也是必须的方法是Play:
1 2 3 4 5 6 |
var animation = dojo.fadeOut({ // returns a dojo._Animation
// this is an Object containing properties used to define the animation
node:"aStringId"
});
// call play() on the returned _Animation instance:
animation.play();
|
如果你以后不再需要这个动画对象,你可以用下面的代码来简化:
1 |
dojo.fadeOut({ node:"someId" }).play();
|
dojo中的所有动画,都是使用对象上的预定义的动画属性来指定动画的设置,node:property是最重要的,指向DOM中的一个结点,对其应用动画动作,node可以是DOM结点一个字符串ID,或者直接引用已有的DOM结点:
1 2 |
var target = dojo.byId("someId").parentNode;
dojo.fadeOut({ node: target }).play();
|
在动画设置中的标准属性集合(动画函数通过对象的参数来调用):
Property | Description |
node |
引用的DOM结点或一个结点的ID串,该结点即应用的动画的结点. required |
delay |
延迟时间,单位毫秒,即动画启动前的时间,默认值为0ms. optional |
duration |
How long, in milliseconds, the animation will run. The default is 350 milliseconds (.35 seconds) optional |
easing |
An easing (timing) function to apply to the effect, such as exponential curve, bounce, etc. Dojo provides a number of easing functions in module dojo.fx.easing optional |
rate |
By default dojo runs its animations with 50 frames/second. This can be too fast in certain scenarios when want the whole animation to run a lot slower. To change the framerate you use the rate property which defines the pause/delay between each frame. Ex. if you want 5 frames per second you should specify a rate of 200 (miliseconds between each frame) optional |
repeat |
How many times the animation will be played. Default: 0. optional |
curve | An array two values, or an instance of a dojo._Line. Used as the start and end points for a given animation. Typically not used directly by end-users, though allows usage of the Animation class outside of Node effects |