小程序拖拽2

2019-07-15  本文已影响0人  野蘑菇丶

index.wxml文件

<viewclass="view" style="left:{{left}}px;top:{{top}}px;"  bindtouchmove="viewTouchMove" >使用鼠标拖动我</view>

index.js文件

Page({

  data:{

    left:'',

    top:''

  },

  viewTouchMove:function(e){

    this.setData({

      left:e.touches[0].clientX-60,

      top:e.touches[0].clientY-60

    })

  }

})

index.wxss文件

.view{

    position: absolute;//有定位才可以

    height:120px;

    width:120px;

    background:green;

    color: white;

    text-align: center;

    line-height: 120px;

}

上一篇 下一篇

猜你喜欢

热点阅读