小程序的movable-view怎么持续移动
在小程序的官方例子中,点击按钮以后的movable-view只是挪动了一次(链接:https://mp.weixin.qq.com/debug/wxadoc/dev/component/movable-view.html),那我想每点击一次就再挪动一个距离怎么弄:
wxml:
<view class="section"> <view class="section__title">movable-view区域小于movable-area</view> <movable-area style="height: 200px;width: 200px;background: red;"> <movable-view style="height: 50px; width: 50px; background: blue;" x="{{x}}" y="{{y}}" direction="all"> </movable-view> </movable-area> <view class="btn-area"> <button size="mini" bindtap="taps">click me to move to (30px, 30px)</button> </view>
js:
Page({ data: { x:0, y:0 }, taps: function (e) { let num = 10; console.log(this.data.x); this.setData({ x: this.data.x+num, y: this.data.x+num }); } })
如此便可以实现功能了