1. 程式人生 > >小程序的movable-view怎麽持續移動

小程序的movable-view怎麽持續移動

blue direct com width 按鈕 brush ini post 點擊

在小程序的官方例子中,點擊按鈕以後的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
    });
  }
})

  如此便可以實現功能了

小程序的movable-view怎麽持續移動