# animation
The animation
module is used to perform animation on components.
JS-Animation can perform a series of simple transformations (position, size, rotation, background color, and opacity) on the component with Javascript.
For example, if you have a image
component, you can move, rotate, grow, or shrink it by animation.
One can invoke animation.transition(ref, options, callback)
to start animation. Ref the following code snippets.
animation.transition(test, {
styles: {
backgroundColor: '#FF0000',
transform: 'translate(250px, 100px)',
},
duration: 800, //ms
timingFunction: 'ease',
needLayout:false,
delay: 0 //ms
}, function () {
modal.toast({ message: 'animation finished.' })
})
Only for Android
It may cause crash with exception Unable to create layer for xxx if the size ( width or height ) of your component with animation
exceeds the maximum as your component makes the OpenGL memory zone OutOfMemory.
The maximum of the size for your component is device dependent, but you are in the danger zone if the size is bigger than screen's size.
TIP
Ref transition or transform if you prefer CSS animation.
# API
# transition
# transition(ref, options, callback)
@ref, the element that will be animated. For example, if the value of
ref
for an element istest
, you can start an animation withthis.$refs.test
.@options, animation properties such as keys, duration.
styles
,styles
specifies the names and values of styles to which a transition effect should be applied. The supported styles are listed below:- width
- height
- backgroundColor
- opacity
- transformOrigin
- transform
- translate/translateX/translateY
- rotate/rotateX/rotateY
- perspective
- scale/scaleX/scaleY
duration
,duration
number specifies the duration of animation execution, the default value is0
, meaning that the component get the desired property immediately.delay
,delay
number specifies the waiting time before the animation starts. The default value is0
.needLayout
,needLayout
boolean Specifies whether the change to layout(width/height/etc..) is persistence and takes affect after the animation. Default value isfalse
timingFunction
,timingFunction
string describes how the intermediate values are calculated for the CSS properties being affected by the animation effect. default value islinear
, the supported values are listed in the following:linear
: Specify a transition effect with the same speed from start to end.ease-in
: Specify a transition effect with a slow start and fast end.ease-out
: Specify a transition effect with a fast start and slow end.ease-in-out
: Specify a transition effect with a slow start, fast intermediate and slow end.cubic-bezier(x1, y1, x2, y2)
: Define your own values in the cubic-bezier function. Possible values are parameter values from 0 to 1. More information about cubic-bezier please visit cubic-bezier and Bézier curve
@callback, callback is a function called after the completion of animation. In iOS platform, you can use function to get information of animation execution.
TIP
- On iOS platform you can get animation's message about completion, there are two types of parameters with
result
, isSuccess
andFail
, Android can not support until now. - Android doesn't support the result parameter.
# Animated properties in styles
width
, thewidth
applied to the component after the animation finished. SetneedLayout
to true if you want the change to be persistence. The default value iscomputed width
.height
, theheight
applied to the component after the animation finished. SetneedLayout
to true if you want the change to be persistence. The default value iscomputed height
.backgroundColor
, thebackgroundColor
applied to the component after the animation finished. The default value iscomputed backgroundColor
.opacity
, theopacity
applied to the component after the animation finished. The default value iscomputed opacity
.transformOrigin
, thetransformOrigin
indicate the pivot of the element being animated. The possible values forx-axis
areleft
/center
/right
/length or percent, and possible values ofy-axis
aretop
/center
/bottom
/ length or percent. The default value iscenter center
.transform
, transform object, which may includerotate
,translate
,scale
and etc. The detail of transform is illustrated below.translate/translateX/translateY
: Specify the location which the element will be translated to.The unit is number or percent and the default value is 0.rotate/rotateX/rotateY
v0.14+: Specify the angle of which the element will be rotated. The unit is degree and the default value is 0.perspective
v0.16+: The distance between the z=0 plane and the user. Supported for Android 4.1 and above. The unit is number and the default value is positive infinity.scale/scaleX/scaleY
: Stretch or shrink the element. The unit is number and the default value is 1. :::