两种方案开发小程序动画
在普通的网页开发中,动画效果可以通过css3来实现大部分需求,在小程序开发中同样可以使用? 指路:?小程序animatiom动画API API解读小程序中,通过调用? 创建这个对象let animation = wx.createAnimation({
duration: 2000,delay: 0,timingFunction: "linear",});
复制代码
这个? 添加动效实例创建完成之后,基于该实例,添加需要的动态效果,动态类型可以查阅文档得知,以最常见的移动,旋转为例: animation.translate($width,0).rotate($deg);
复制代码
结束动画
.step();
复制代码
导出动画动画效果添加完成了,如何给想要的dom添加动效呢。这里需要用到? <view animation="{{moveOne}}"></view>
复制代码
例子以下将通过2组动画,来对比一下? 一、模块移动动画动画效果:下图有两组动画,分别为? 代码实现以下分别为? css3:<!-- wxml -->
<view class='border'>
<'css-block {{isMove && "one"}}'></view>
<{{isMove && "two"}{{isMove && "three"}{{isMove && "four"}view>
</view>
复制代码
// scss
@mixin movePublic($oldLeft,$oldTop,96);">$left,96);">$top) {
from {
transform:translate($oldTop);
}
to {
$top);
}
}
@mixin blockStyle($color,96);">$name) {
background: $color;
animation:$name 2s linear infinite alternate;
}
.one {
@include blockStyle(lightsalmon,onemove);
}
@keyframes onemove {
@include movePublic(50rpx,-25rpx,0);">150rpx,0rpx);
}
.two {
@include blockStyle(lightblue,twomove);
}
@keyframes twomove {
@0rpx,0);">.three {
@include blockStyle(lightgray,threemove);
}
@keyframes threemove {
@.four {
@include blockStyle(grey,fourmove);
}
@keyframes fourmove {
@include movePublic(-0rpx);
}
复制代码
css3?中通过动态改变?
// js
playTwo(){
this.setData({
playTwo: !this.data.playTwo
},()=>{
let back = data.backgroundAudioManager;
if(data.playTwo){
back.play();
} else {
back.pause();
}
})
}
复制代码
通过? api: bindtap='play' animation={{play && musicRotate}}">
<{{play}{{!play}view>
复制代码
api?实现的方式是通过移除? |