小程序動(dòng)畫插件,更方便地將所需的動(dòng)畫css注入到對(duì)應(yīng)的元素中,使動(dòng)畫邏輯更可控
import {Animation, AnimationGroup, AnimationAssign} from '../../Animation/Animation';wxml 中添加 //Animation .fadeOutToButton-enter{ opacity: 0.01; transform: translateY(-50%); } .fadeOutToButton-enter.fadeOutToButton-enter-active{ opacity: 1; transform: translateY(0); transition: all 1000ms ease-in; } .fadeOutToButton-exit{ opacity: 1; transform: translateY(0); } .fadeOutToButton-exit.fadeOutToButton-exit-active{ opacity: 0.01; transform: translateY(50%); transition: all 1000ms ease-in; }初始化 在onLoad 函數(shù)中: onLoad:function(options){ //Animation this.fadeOutToButton = new Animation(this,{ className: 'fadeOutToButton', // 寫在css的樣式名 animationName: 'fade', // 填寫在html中的變量名 timeOut: 1000, //動(dòng)畫時(shí)間 和動(dòng)畫持續(xù)時(shí)間同步 // delayTime: 1000, // 延遲時(shí)間 }) //AnimationGroup this.fadeArr = new AnimationGroup(this,{ className: 'fadeOutToButton', // 寫在css的樣式名 animationName: 'fadeArr', // 填寫在html中的變量名 timeOut: 1000, //動(dòng)畫時(shí)間 和動(dòng)畫持續(xù)時(shí)間同步 // delayTime: 1000, // 延遲時(shí)間 interval: 200, }) //AnimationAssign this.removeAnimation = new AnimationAssign(this,{ className: 'fadeOutToButton', animationName: 'fadeArr', timeOut:1000, }) },調(diào)用 在 onShow 函數(shù)中: (當(dāng)元素一開始存在時(shí))
onShow: function () {
this.fadeOutToButton.in()
},
當(dāng)元素開始并不存在 (會(huì)先顯示元素之前先添加上 enter類)
// 可傳入延遲時(shí)間 毫秒 不填會(huì)根據(jù)構(gòu)造時(shí)的延遲時(shí)間來控制 this.fadeOutToButton.in(1000).then(()=>{ this.setData({ boxShow: true, }) }) 消除元素 (會(huì)先元素消失之后在消失元素) this.fadeOutToButton.out().then(()=>{ this.setData({ boxShow: false, }) }) |