小程序怎么实现下拉刷新

小程序怎么实现下拉刷新,第1张

方法一:

在 appjson  中,设置"enablePullDownRefresh": true,    开启全局下拉刷新。或者通过在单组件的 json ,  设置"enablePullDownRefresh": true,  单组件下拉刷新。

方法二:

使用滚动组件scroll-view自定义刷新,通过(绑定)bindscrolltoupper属性, 当滚动到顶部/左边,会触发 scrolltoupper事件,从而实现下拉刷新功能。

微信小程序 ,列表头滚动的过程中 ,view  悬浮在顶部  ,如何实现这样的一个效果呢??

//indexjs

//获取应用实例

const app = getApp()

Page({

  data: {

    testData: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],

    testData2: [1, 2, 3, 4, 5,  10],

    //是否显示 悬停布局

    isshow:false,

    //悬浮布局的数据

    toptexxt:""

  },

  onLoad: function () {

  },

  /

页面加载完成

/

  onReady: function () {

  },

  /

页面滚动监听

/

  onPageScroll: function (e) {

    //consolelog(e)

    let that = this

    let query = wxcreateSelectorQuery()

    queryselectAll("section-cell")boundingClientRect(function (res) {

      consolelog(res)

      let size =reslength;

      let position = -1;

      let topshow = -1000;//根据需求设置大小

      let i=0;

      //根据 top  的 大小 获取 当前距离顶部最近的view 的下标, 负数最大值 或者是0,

      for(i=0;i<size;i++){0

        let top = res[i]top;

        if(top<=0 && top>topshow ){

          topshow = top;

          position=i;

        }

      }

      consolelog("当前坐标是 position = "+position)

      let isshow =false;

      if (res[0]top<0){

        if(position==-1) position=0;

          isshow = true;

      }

      thatsetData({

        isshow: isshow,

        toptexxt: isshowthatdatatestData[position]:""

      })

    })exec()

  },

})

<!--indexwxml-->

<view>

  <view class='header'>这里是header</view>

  <view hidden='{{!isshow}}'>

    <view class= "section-header section-fixed" >这是section-header {{toptexxt}}</view>

  </view>

  <view wx:for="{{testData}}" wx:key="{{testData}}">

    <view>

      <view class='section-cell' id='top{{item}}'>{{item}} </view>

      <view wx:for="{{testData2}}" wx:key="{{testData2}}">

        <view class='section-cell2' id='child{{item}}'>{{item}}</view>

      </view>

    </view>

  </view>

</view>

/indexwxss/

section-placeholder {

  background-color: white;

}

section-fixed {

  position: fixed;

  top: 0;

}

header {

  height: 300rpx;

  width: 750rpx;

  background-color: bisque;

}

section-header {

  height: 80rpx;

  width: 750rpx;

  background-color: rebeccapurple;

}

section-cell {

  width: 750rpx;

  height:80rpx;

  background-color: gold;

  margin-top: 2rpx;

}

section-cell2 {

  height: 50rpx;

  width: 750rpx;

  background-color: darkred;

}

效果

以上就是关于小程序怎么实现下拉刷新全部的内容,包括:小程序怎么实现下拉刷新、微信小程序 ,列表头滚动的过程中 view 悬浮在顶部、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/9865099.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存