本篇文章给大家带来的内容是关于小程序实例:如何自定义下拉刷新,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
自定义组件:
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: '松开加载', scrollHeight: dY }) } else if (dY > 80) { this.setData({ tips: '松开加载', scrollHeight: 80 }) } else { this.setData({ tips: '下拉刷新', 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='loading-container' bindtouchend='end' bindtouchmove='move' bindtouchstart='start' style='margin-top:{{scrollHeight}}px;transform:translateY(-50px);' > <view class="weui-loadmore" style='margin:0 auto;padding:1.5em 0;'> <view class="weui-loading"></view> <view class="weui-loadmore__tips">{{tips}}</view> </view> </view>
wxss:其中引用了weui 这个用不用都无所谓的很简单的
@import '/pages/common/weui.wxss'; page{ height: 100%; } .loading-container{ height: 100%; }
pages里wxml:
<loadmore style='height:100%;' bindonRefresh='onRefresh' id='loadmore'></loadmore>
js://刷新方法回调
onRefresh: function() { var that = this; setTimeout(function(){ that.selectComponent("#loadmore").stopRefresh(); },3000) }, json: { "enablePullDownRefresh": false, "usingComponents":{ "loadmore":"../../components/test/test" } }
以上是小程序实例:如何自定义下拉刷新的详细内容。更多信息请关注PHP中文网其他相关文章!
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
刺客信条阴影:贝壳谜语解决方案
2 周前ByDDD
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

记事本++7.3.1
好用且免费的代码编辑器

Atom编辑器mac版下载
最流行的的开源编辑器