请教,我想通过for循环,把animation分别绑定到对象上,该怎做?
目前我按如下方法尝试,但似乎没有效果
<view class='replyPieceAll' wx:for='{{arr_replyL}}' animation="{{arr_an}}" style='transform:rotate({{arr_replyL[index].angle}}deg); transform-origin:{{needLeft}}rpx 20rpx;'>
this.data.arr_an[0].opacity(0).step();
this.setData(
{
arr_an: this.doAn(),
}
doAn:function ()
{
this.data.arr_an[0].opacity(0).step().export();
return this.data.arr_an
}
setData这里怎么写呢?没反应
item.animation.opacity(0).step().export()
this.setData(
{
pels:this.data.pels
}
)
我只是写法例子。。不是可以用的代码啊。。我给你写个可以直接用的吧,稍等
谢谢您
let animationArray = []
Page({
data: {
array: [1,2,3],
animationArray: []
},
onLoad:
function
() {
this
.data.array.forEach(()=>{
let animation = wx.createAnimation({
duration: 500
})
animationArray.push(animation)
})
},
tapFn:
function
(e) {
let index = e.currentTarget.dataset.index
this
.data.animationArray[index] = animationArray[index].translate(100,100).step().export()
this
.setData({
animationArray:
this
.data.animationArray
})
}
})
<
view
style
=
'width:100%;height:100%'
>
<
block
wx:for
=
"{{array}}"
wx:key
=
"index"
>
<
view
style
=
"width:50rpx;height:50rpx;background:red;border:1rpx solid green"
data-index
=
"{{index}}"
bindtap
=
"tapFn"
animation
=
"{{animationArray[index]}}"
></
view
>
</
block
>
</
view
>
粘贴代码会有些莫名其妙的空格,注意清除哈。。