找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

关于scroll-view和下拉刷新的那些坑

作者:模板之家 2018-1-25 08:47 10308人关注

众所周知,小程序不支持操作dom元素,但最近公司做了这样的一个功能,滚动scrollview 标签,当页面滚动到一定的高度时,给页面一个固定导航,并且还要执行下拉加载的方法。由于在官

众所周知,小程序不支持操作dom元素,但最近公司做了这样的一个功能,滚动scrollview 标签,当页面滚动到一定的高度时,给页面一个固定导航,并且还要执行下拉加载的方法。由于在官方文档的说明中,使用竖向滚动时,需要给<scroll-view/>一个固定高度,通过 WXSS 设置 height。但是设置了高度的时候,下拉加载的方法就不好使了。这时候我们要根据滚动的高度来设置不同的高度,部分代码如下:
<scroll-view scroll-y="true" style="height: {{scrollViewHeight}}rpx;" bindscroll="scrollviewScroll" bindscrolltolower="getNextPage">
  <view class="brand">
    <image class="brand-image" src="{{logo_url}}" mode="widthFix" />
    <text class="description">{{description}}</text>
  </view>
  <view class="tab" style="position:{{fixedTop ? 'fixed' : 'static'}}">


JS

  scrollviewScroll:function(e){
    var viewScrollTop = e.detail.scrollTop;
    var scrollTop = this.data.scrollTop;
    if(viewScrollTop > scrollTop){
      this.setData({
        fixedTop:true
      });
    }else{
      this.setData({
        fixedTop:false
      });
    };
  },


    wx.getSystemInfo({
      success: function (res) {
        var scrollViewHeight = 750 * res.windowHeight / res.windowWidth; //rpx
        console.log(res.windowWidth)
        var scrollTop = res.windowWidth * 400 / 750; //矢量转换后的高度
        that.setData({
          scrollViewHeight: scrollViewHeight,
          scrollTop: scrollTop,
          fixedTop: false
        });
      }
    });

路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)