网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序之判斷頁面滾動方向

發布時間:2018-09-01 09:28 所屬欄目:小程序開發教程

需求

微信小程序中如果判斷頁面滾動方向?

解決方案

1.用到微信小程序API

 

2.獲取頁面實際高度

<!--WXML-->
<view id="box">
   <view class="list" wx:for="{{List}}" wx:key="List{{index}}">
        <image mode='aspectFill' class='list_img'  src="{{item.imgUrl}}"  ></image>
   </view>
</view>
    /* JS */
  // 封裝函數獲取ID為box的元素實際高度 
  getScrollHeight: function() {
    wx.createSelectorQuery().select('#box').boundingClientRect((rect) => {
      this.setData({
        scrollHeight: rect.height
      })
      console.log(this.data.scrollHeight)
    }).exec()
  },
  // 假設數據請求
  getDataList: function() {
    wx.request({
      url: 'test.php', //僅為示例,并非真實的接口地址
      success: function(res) {
      // 如果該元素下面的數據是動態獲取的,此方法在wx.request請求成功的回調函數中調用
        this.getScrollHeight()
      }
    })
  },

3.監聽用戶滑動頁面事件

    //監聽用戶滑動頁面事件
  onPageScroll: function(e) {
   
    if (e.scrollTop <= 0) {
     // 滾動到最頂部
      e.scrollTop = 0;
    } else if (e.scrollTop > this.data.scrollHeight) {
      // 滾動到最底部
      e.scrollTop = this.data.scrollHeight;
    }
    if (e.scrollTop > this.data.scrollTop || e.scrollTop >= this.data.scrollHeight) {
      //向下滾動 
      console.log('向下 ', this.data.scrollHeight)
    } else {
      //向上滾動 
      console.log('向上滾動 ', this.data.scrollHeight)
    }
    //給scrollTop重新賦值 
    this.setData({
      scrollTop: e.scrollTop
    })
  },


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/24748.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×