search
HomeWeChat AppletMini Program DevelopmentMini program example: How to customize pull-down refresh

The content of this article is about small program examples: how to customize pull-down refresh. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Custom component:

js:

// components/test/test.js
Component({
/**
* 组件的属性列表
*/
properties: {
 
},
 
/**
* 组件的初始数据
*/
data: {
scrollHeight: 0,
startY: 0,
tips: '下拉刷新',
isRefreshing: false
},
 
/**
* 组件的方法列表
*/
methods: {
end: function(e) {
if (this.data.isRefreshing) {
return
}
if (this.data.scrollHeight >= 50) {
this.setData({
scrollHeight: 50,
tips: '正在刷新',
isRefreshing: true
})
this.triggerEvent('onRefresh')
} else {
this.setData({
scrollHeight: 0,
tips: '下拉刷新'
})
}
},
move: function(e) {
if (this.data.isRefreshing) {
return
}
 
var that = this;
var moveY = e.touches[0].pageY;
var dY = moveY - that.data.startY;
console.log(dY);
if (dY >= 50 && dY <= 80) {
this.setData({
tips: &#39;松开加载&#39;,
scrollHeight: dY
})
} else if (dY > 80) {
this.setData({
tips: &#39;松开加载&#39;,
scrollHeight: 80
})
} else {
this.setData({
tips: &#39;下拉刷新&#39;,
scrollHeight: dY
})
}
 
},
 
start: function(e) {
this.data.startY = e.touches[0].pageY;
},
 
stopRefresh: function() {
this.setData({
isRefreshing: false,
scrollHeight: -50
})
},
}
})

wxml:

<!--components/test/test.wxml-->
<view class=&#39;loading-container&#39; bindtouchend=&#39;end&#39; bindtouchmove=&#39;move&#39; bindtouchstart=&#39;start&#39; style=&#39;margin-top:{{scrollHeight}}px;transform:translateY(-50px);&#39; >
<view class="weui-loadmore" style=&#39;margin:0 auto;padding:1.5em 0;&#39;>
<view class="weui-loading"></view>
<view class="weui-loadmore__tips">{{tips}}</view>
</view>
</view>

wxss: It references weui which is very simple and it doesn’t matter whether you use it or not

@import &#39;/pages/common/weui.wxss&#39;;
page{
height: 100%;
}
 
.loading-container{
height: 100%;
}

wxml in pages:

<loadmore style=&#39;height:100%;&#39; bindonRefresh=&#39;onRefresh&#39; id=&#39;loadmore&#39;></loadmore>

js://refresh method callback

onRefresh: function() {
var that = this;
setTimeout(function(){
that.selectComponent("#loadmore").stopRefresh();
},3000)
},
json:
{
"enablePullDownRefresh": false,
"usingComponents":{
"loadmore":"../../components/test/test"
}
}

The above is the detailed content of Mini program example: How to customize pull-down refresh. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools