关于animation搭配wx:for的问题
发布于 5 年前 作者 yongqian 10340 次浏览 来自 问答

后一个view顶上去的时候会直接引用前一个view的动画

<view >

<view wx:for="{{testanimations}}" wx:key="{{item.i}}" bindtap=‘test’ data-value="{{item.i}}" animation="{{item.o}}">{{item.i}}</view>

<button bindtap=‘test2’>asd</button>

</view>

data: {

    testanimations:[

        {

            i:0,

            o:null

        },

        {

            i: 1,

            o: null

        },

    ],

},

test:function(index) {

    var that=this

    let value=index.currentTarget.dataset.value

    let animation = wx.createAnimation({

        duration: 1000,

        timingFunction: ‘ease’

    })

    animation.translateX(500).step()

    var animationsTemp = this.data.testanimations

    animationsTemp[value].o = animation.export()

    this.setData({

        testanimations: animationsTemp

     })

    setTimeout(function(){

        var animationsTemp2 = that.data.testanimations

        animationsTemp2.splice(value,1)

        that.setData({

            testanimations: animationsTemp2

        })

    },1000)

}

回到顶部