HomeDocs
Skip to main content

Animation

Common Ways to Create Interface Animations​

In a mini-program, you can typically use CSS gradients and CSS animations to create simple interface animations.

You can also use the dlt.createAnimation interface to dynamically create simple animation effects.

Parameter Descriptions​

PropertyTypeRequiredDefaultDescription
durationNumberNo400Duration of the animation (ms).
timingFunctionStringNo'linear'Defines the animation effect.
delayNumberNo0Delay time of the animation (ms).
transformOriginStringNo'50% 50% 0'Animation transform origin.

Valid timingFunction Values​

ValueDescription
linearConstant speed throughout the animation.
easeSlow start, then fast, then slow finish.
ease-inSlow start for the animation.
ease-in-outSlow start and slow finish.
ease-outSlow finish for the animation.
step-startJumps to the end state on the first frame and stays in that state until the end.
step-endStays in the start state until the last frame, then jumps to the end state.

Example Code

<view class="wrap">
<view
class="anim"
bind:tap="startToAnimate"
:animation="animationData"
></view>
</view>
Page({
data: {
animationData: {},
},
startToAnimate() {
const animation = dlt.createAnimation({
transformOrigin: "50% 50%",
duration: 1000,
// timingFunction options: ease, ease-in, ease-in-out, ease-out, step-start, step-end
timingFunction: "linear",
delay: 0,
});
animation.rotate(90).translateY(10).step();
this.setData({
animationData: animation.export(),
});
console.log("createAnimation", animation);
},
});
Privacy agreementDeveloper agreementcontact us: developer_private.mi@dlightek.com © 2024 MiniApp. All Rights Reserved.