代码:

  //页面上拉触底事件的处理函数
onReachBottom(e) {
console.log("底部")// 滚动到页面执行 该 方法
wx.showToast({
title: '加载中...',
icon: 'loading',
duration:
})
/*
这里执行你需要的请求数据追加到循环数组就好了
*/
},
onPageScroll(e) {
console.log(e) //滚动条 滚动的位置(e.scrollTop)从头部开始计算
},

原理:

上拉加载更多这个需求我相信应该应用颇为广泛的,今天说我认为两种可行的方式哈 。

一、第一个应该是最简单的一种实现方式,文档自带的一个api 可以监听滚动到页面底部的方法(onReachBottom) 、"onPageScroll"方法可以监听页面滚动条的位置。(PS:页面.json 中'onReachBottomDistance:number'默认为50,这个可以设置在距离底部多少px执行onReachBottom方法,具体使用看你需求。)
1.首先准备几个盒子 使其 超出page 页面高度产生滚动条、然后准备一个加载动画具体实现如下:

//wxml: arr是length为4的数组随意定义 只是为了撑高度的
<view class='warp'>
<view wx:for="{{arr}}" class='bg_cl'></view>
</view>
<!--加载动画 -->
<view class='bottom'>
<view class="loading">
<text></text>
<text></text>
<text></text>
<text></text>
<text></text>
</view>
</view>
// wxss ========================================
.warp{
display: flex;
flex-flow: column;}
.bg_cl{
width: %;
flex: ;
height: 400rpx;
background: pink;}
.bg_cl:nth-child(),.bg_cl:nth-child(){
background: purple;}
.bottom{
line-height: 50rpx;
font-size: 24rpx;
display: flex; align-items: center;
justify-content: center;} /*过渡动画 */
.loading{
width: 148rpx;
height: 44rpx;}
.loading text{
display: inline-block;
width: 20rpx;
height:20rpx;
margin-right: 5px;
border-radius: %;
background:#;
-webkit-animation: load .04s ease infinite;
}
.loading text:last-child{
margin-right: 0px;
}
@-webkit-keyframes load{
%{
opacity: ;
-webkit-transform: scale();
}
%{
opacity: 0.2;
-webkit-transform: scale(.);
}
}
.loading text:nth-child(){
-webkit-animation-delay:.13s;
}
.loading text:nth-child(){
-webkit-animation-delay:.26s;
}
.loading text:nth-child(){
-webkit-animation-delay:.39s;
}
.loading text:nth-child(){
-webkit-animation-delay:.52s;
}
.loading text:nth-child(){
-webkit-animation-delay:.65s;
} //js=========================================================
onReachBottom(e){
console.log("底部")// 滚动到页面执行 该 方法
wx.showToast({
title: '加载中...',
icon:'loading',
duration:
})
/*
这里执行你需要的请求数据追加到循环数组就好了
*/
},
onPageScroll(e){
//console.log(e) //滚动条 滚动的位置(e.scrollTop)从头部开始计算
},
 
 

第二种:可以用 scroll-view 组件,scroll-y为true 时允许纵向滚动、使用scroll-view 组件时需要设置固定的高度。组件中有一个bindscrolltolower 触底 /右边 方法。详情见官方文档(PS: 使用组件会在页面产生一个滚动条,而page中也会有一个此时会出现问题,可以在页面 .json配置文件中 设置:"disableScroll":true 页面整体不能上下滚动 等价于 wxss 中page{overflow:hidden} ;)

<!-- scroll-view  -->
<scroll-view scroll-y='true' style="height:{{height}}px" bindscroll='scrollt' bindscrolltolower='scrollBottom'>
<view class='warp'>
<view wx:for="{{arr}}" class='bg_cl'></view>
</view>
</scroll-view>
==============wxss 延用上方就好了 下方是js'=================
onLoad: function () {
var that=this
wx.getSystemInfo({
success:res=>{
console.log(res)
this.setData({
height: res.windowHeight //获取屏幕高度 赋值给scroll-view
})
}
})
},
//scroll- view 滚动条 距顶部多少px
scrollt(e){
console.log(e.detail)
},
// scroll-view 滚动到底部触发
scrollBottom(e){
console.log(" 我是scroll 的底部")
//此处添加你的 请求方法就好了 这里不多做赘述了。
}

.

微信小程序~上拉加载onReachBottom的更多相关文章

  1. 微信小程序上拉加载:onReachBottom详解+设置触发距离

    前端经常遇到上拉加载更多的需求,一般还涉及到翻页.小程序里已经给了下拉到底的触发方法onReachBottom(),这里记录下怎样使用这个方法实现下拉加载更多,有需要的直接看代码,有详细注释: 1.首 ...

  2. 微信小程序上拉加载下拉刷新

    微信小程序实现上拉加载下拉刷新 使用小程序默认提供方法. (1). 在xxx.json 中开启下拉刷新,需要设置backgroundColor,或者是backgroundTextStyle ,因为加载 ...

  3. 微信小程序 - 上拉加载下拉刷新

    点击下载示例:小程序 - 上拉刷新下拉加载

  4. 微信小程序 - 上拉加载

    demo.wxml  文件 <view wx:for="{{listdata}}" wx:key="listdata" class='listitem'& ...

  5. 微信小程序上拉加载——分页

    wxml: <view class="page"> <scroll-view class="imageViewCss_1" scroll-y= ...

  6. 微信小程序 - 上拉加载更多组件

    详情用例看demo,点击下载示例:loadmore

  7. 微信小程序之下拉加载和上拉刷新

    微信小程序下拉加载和上拉刷新两种实现方法 方法一:onPullDownRefresh和onReachBottom方法实现小程序下拉加载和上拉刷新 首先要在json文件里设置window属性       ...

  8. 微信小程序下拉加载和上拉刷新两种实现方法

    方法一:onPullDownRefresh和onReachBottom方法实现小程序下拉加载和上拉刷新 首先要在json文件里设置window属性 设置js里onPullDownRefresh和onR ...

  9. 微信小程序之上拉加载更多

    loadmore 加载更多(分页加载) 当用户打开一个页面时,假设后台数据量庞大时,一次性地返回所有数据给客户端,页面的打开速度就会有所下降,而且用户只看上面的内容而不需要看后面的内容时,也浪费用户流 ...

随机推荐

  1. Emiya 家今天的饭

    \(dp_{i,j,k}\)表示前\(i\)种烹饪方法,假设最多的是食材\(j\),食材\(j\)比其他食材多\(k\)次出现 其中\(i \in [1,n],j \in [1,m],k \in [- ...

  2. pandas 模块

    什么是pandas pandas是一个python的包,主要用来处理表格格式的文件,可以快速的对表格进行查询,过滤,合并等操作. pandas的简单使用 pandas读入table格式文件 #读入一个 ...

  3. 快排 PAT 1101

    1101 Quick Sort (25 分)   There is a classical process named partition in the famous quick sort algor ...

  4. git pull 出现 WARNING: POSSIBLE DNS SPOOFING DETECTED!

    此时不管你是git pull 还是clone 都报错如下: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: ...

  5. Ubuntu18.04LTS python3.6 cuda10.0 下安装低版本的pytorch

    Ubuntu18.04LTS python3.6 cuda10.0 下安装低版本的pytorch,运行Hypergraph Neural Networks(HGNN) https://github.c ...

  6. Spring security oauth2 password flow

    Spring security oauth2 包含以下两个endpoint来实现Authorization Server: AuthorizationEndpoint: 授权请求访问端点, 默认url ...

  7. 我瞅瞅源码系列之---drf

    我瞅瞅源码系列之---drf restful规范 从cbv到drf的视图 / 快速了解drf 视图 版本 认证 权限 节流 jwt 持续更新中...

  8. Spark之RDD弹性特性

    RDD作为弹性分布式数据集,它的弹性具体体现在以下七个方面. 1.自动进行内存和磁盘数据存储的切换 Spark会优先把数据放到内存中,如果内存实在放不下,会放到磁盘里面,不但能计算内存放下的数据,也能 ...

  9. vue 异步渲染

    <!DOCTYPE html> <html> <head> <title> hello world vue </title> <met ...

  10. 移动端的touch click事件的理解+点透

    移动端在touch上一共有4个事件 touchstart touchmove touchend touchcancel, touchcancel, 一般来说,它们执行的顺序为 touchstart - ...