title: animation type: references order: 9.01 version: 2.1

Animation

Overview

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.

Note: Ref transition or transform if you want to use CSS animation.

Basic Usage

animation.transition(ref, options, callback)

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.' })
    })

Attributes

ref

The element that will be animated.

For example, if the value of ref for an element is test, you can start an animation with this.$refs.test.

options

  • styles (object): Specify the names and values of styles to which a transition effect should be applied. The supported styles are listed in the following table:

    namedescriptionvalue typedefault value
    widthThe width applied to the component after the animation finished. Set needLayout to true if you want the change to be persistence.lengthcomputed width
    heightThe height applied to the component after the animation finished. Set needLayout to true if you want the change to be persistence.lengthcomputed height
    backgroundColorThe background color applied to the component after the animation finished.stringcomputed backgroundColor
    opacityThe opacity applied to the component after the animation finished.number between 0 to 1computed opacity
    transformOriginThe pivot of transition. The possible values for x-aris are left/center/right/length or percent, and possible values of y-axis are top/center/bottom/ length or percentx-axis y-axiscenter center
    transformTransform object, which may include rotate, translate, scale and etc.objectnone
    • The following table illustrate the detail of transform.

      namedescriptionvalue typedefault value
      translate/translateX/translateYSpecifies the location which the element will be translated to.pixel or percent0
      rotate/rotateX v0.14+ /rotateY v0.14+Specifies the angle of which the element will be rotated, the unit is degree.number0
      perspective v0.16+3D perspective. The distance between the z=0 plane and the user. Supported for Android 4.1 and above.numberpositive infinity
      scale/scaleX/scaleYStretch or shrink the element.number1
  • duration (number): Specify the duration of animation execution, the default value is 0, meaning that the component get the desired property immediately.

  • delay (number): Specify the waiting time before the animation starts. The default value is 0.

  • needLayout(boolean):Whether the change to layout(width/height/etc..) is persistence and takes affect after the animation. Default value is false

  • timingFunction (string): Used to describe how the intermediate values are calculated for the CSS properties being affected by the animation effect. default value is linear, the supported values are listed in the following table:

    namedescription
    linearSpecifies a transition effect with the same speed from start to end
    easeSpecifies a transition effect with a slower and slower speed
    ease-inSpecifies a transition effect with a slow start
    ease-outSpecifies a transition effect with a slow end
    ease-in-outSpecifies a transition effect with a slow start and 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.

Note: after WeexSDK0.16.0, in iOS platform can get animation's message about completion, there are two types of parameters with result, is Successand Fail, Android can not support until now.

Note: Android doesn't support the result parameter.

Example