亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序?qū)崿F(xiàn)拖拽功能

 更新時間:2019年09月26日 11:49:00   作者:前端_李嘉豪  
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)拖拽功能,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

<view class='collectBox' 
  bindtap='addCollect' 
  wx:if="{{write[0]+write[1] > 0}}" 
  bindtouchmove="touchmove" 
  catch:touchmove 
  style="left:{{write[0]}}px;top:{{write[1]}}px;">
  <image src='../../images/icon/addcollect.png'></image>
</view>
// pages/cateDetaile/cateDetaile.js
const app = getApp()
Page({
 
  /**
   * 頁面的初始數(shù)據(jù)
   */
  data: {
    // 拖拽參數(shù)
    writePosition: [80, 90], //默認定位參數(shù)
    writesize: [0, 0],// X Y 定位
    window: [0, 0], //屏幕尺寸
    write: [0, 0], //定位參數(shù)
    scrolltop: 0,//據(jù)頂部距離
  },
 
  /**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */
  onLoad: function (options) {
    // 在頁面中定義插屏廣告
    let that = this;
    that.getSysdata();
  },
  //計算默認定位值
  getSysdata: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (e) {
        that.data.window = [e.windowWidth, e.windowHeight];
        var write = [];
        write[0] = that.data.window[0] * that.data.writePosition[0] / 100;
        write[1] = that.data.window[1] * that.data.writePosition[1] / 100;
        console.log(write,45)
        that.setData({
          write: write
        }, function () {
          // 獲取元素寬高
          wx.createSelectorQuery().select('.collectBox').boundingClientRect(function (res) {
            console.log(res.width)
            that.data.writesize = [res.width, res.height];
          }).exec();
        })
      },
      fail: function (e) {
        console.log(e)
      }
    });
  },
  //開始拖拽  
  touchmove: function (e) {
    var that = this;
    var position = [e.touches[0].pageX - that.data.writesize[0] / 2, e.touches[0].pageY - that.data.writesize[1] / 2 - this.data.scrolltop];
    that.setData({
      write: position
    });
  },
  onPageScroll(e) {
    this.data.scrolltop = e.scrollTop;
  },
})

總結(jié)

以上所述是小編給大家介紹的微信小程序?qū)崿F(xiàn)拖拽功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關文章

最新評論