极乐门资源网 Design By www.ioogu.com
本文实例讲述了jQuery实现的上拉刷新功能组件。分享给大家供大家参考,具体如下:
技术要点:
1、jQuery的插件写法
2、上拉刷新步骤分解
3、css样式
jQuery的插件写法:
$.fn.pluginName = function() { return this.each(function () { fn(); }) };
上拉刷新步骤分解:
上拉刷新可以分解成三个部分:一是开始(start),记录当前鼠标的位置;二是移动(move),根据下拉的位移响应不同的视图;三是结束(end),刷新页面。
;!function ($) { "use strict"; var PTR = function (ele) { this.container = $(ele); this.container.addClass('pull-to-refresh'); this.distance = 60; // 设置参考的下拉位移 this.attachEvent(); }; // 判断是否有touch事件发生 var isTouch = (function () { var isSupportTouch = !!'ontouchstart' in document || window.documentTouch; return isSupportTouch; })(); var touchEvents = { start: isTouch "htmlcode"><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="pull-to-refresh.css" rel="external nofollow" > <style> p { margin-top: 0; } </style> </head> <body> <div class="pull-to-refresh_layer"> <div class="pull-to-refresh-arrow">↓</div> <div class="pull-to-refresh-preloader"></div> <div class="down">下拉刷新</div> <div class="up">释放刷新</div> <div class="refresh">正在刷新</div> </div> <div> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus amet aperiam, architecto at aut beatae dignissimos eaque est ex fugi at incidunt inventore natus nemo nostru m omnis quos repellat ut voluptas! </p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus amet aperiam, architecto at aut beatae dignissimos eaque est ex fugi at incidunt inventore natus nemo nostru m omnis quos repellat ut voluptas! </p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus amet aperiam, architecto at aut beatae dignissimos eaque est ex fugi at incidunt inventore natus nemo nostru m omnis quos repellat ut voluptas! </p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus amet aperiam, architecto at aut beatae dignissimos eaque est ex fugi at incidunt inventore natus nemo nostru m omnis quos repellat ut voluptas! </p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus amet aperiam, architecto at aut beatae dignissimos eaque est ex fugi at incidunt inventore natus nemo nostru m omnis quos repellat ut voluptas! </p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus amet aperiam, architecto at aut beatae dignissimos eaque est ex fugi at incidunt inventore natus nemo nostru m omnis quos repellat ut voluptas! </p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus amet aperiam, architecto at aut beatae dignissimos eaque est ex fugi at incidunt inventore natus nemo nostru m omnis quos repellat ut voluptas! </p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus amet aperiam, architecto at aut beatae dignissimos eaque est ex fugi at incidunt inventore natus nemo nostru m omnis quos repellat ut voluptas! </p> </div> <script src="/UploadFiles/2021-04-02/jquery-1.8.3.min.js">CSS代码如下:
.pull-to-refresh { margin-top: -50px; transition: transform .4s; } .pull-to-refresh .pull-to-refresh-preloader, .pull-to-refresh .up, .pull-to-refresh .refresh { display: none; } .pull-to-refresh.refreshing { transform: translate3d(0,50px,0); } .refreshing .pull-to-refresh-arrow, .refreshing .down, .refreshing .up { display: none; } .refreshing .refresh, .refreshing .pull-to-refresh-preloader { display: inline-block; } .pull-to-refresh_layer { height: 30px; line-height: 30px; padding-bottom: 10px; } .pull-down .pull-to-refresh_layer .up, .pull-down .pull-to-refresh_layer .refresh { display: none; } .pull-down .pull-to-refresh_layer .down{ display: inline-block; } .pull-up .pull-to-refresh_layer .up{ display: inline-block; } .pull-up .pull-to-refresh_layer .down, .pull-up .pull-to-refresh_layer .refresh { display: none; } .pull-up .pull-to-refresh-arrow { transform: rotate(180deg) translate3d(0, 0, 0); } .pull-to-refresh-arrow { display: inline-block; z-index: 10; margin-right: 4px; transition-duration: 300ms; transform: rotate(0deg) translate3d(0, 0, 0); } .pull-to-refresh_layer { display: inline-block; } .pull-to-refresh-preloader { display: inline-block; } .pull-down { } .pull-up { } .down { display: inline-block; } .up { display: inline-block; } .refresh { display: inline-block; }感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具 http://tools.jb51.net/code/HtmlJsRun 测试上述代码运行效果。
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery页面元素操作技巧汇总》、《jQuery常见事件用法与技巧总结》、《jQuery常用插件及用法总结》、《jQuery扩展技巧总结》及《jquery选择器用法总结》
希望本文所述对大家jQuery程序设计有所帮助。
标签:
jQuery,上拉刷新,组件
极乐门资源网 Design By www.ioogu.com
极乐门资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
极乐门资源网 Design By www.ioogu.com
暂无jQuery实现的上拉刷新功能组件示例的评论...
更新日志
2024年11月18日
2024年11月18日
- 【雨果唱片】中国管弦乐《鹿回头》WAV
- APM亚流新世代《一起冒险》[FLAC/分轨][106.77MB]
- 崔健《飞狗》律冻文化[WAV+CUE][1.1G]
- 罗志祥《舞状元 (Explicit)》[320K/MP3][66.77MB]
- 尤雅.1997-幽雅精粹2CD【南方】【WAV+CUE】
- 张惠妹.2007-STAR(引进版)【EMI百代】【WAV+CUE】
- 群星.2008-LOVE情歌集VOL.8【正东】【WAV+CUE】
- 罗志祥《舞状元 (Explicit)》[FLAC/分轨][360.76MB]
- Tank《我不伟大,至少我能改变我。》[320K/MP3][160.41MB]
- Tank《我不伟大,至少我能改变我。》[FLAC/分轨][236.89MB]
- CD圣经推荐-夏韶声《谙2》SACD-ISO
- 钟镇涛-《百分百钟镇涛》首批限量版SACD-ISO
- 群星《继续微笑致敬许冠杰》[低速原抓WAV+CUE]
- 潘秀琼.2003-国语难忘金曲珍藏集【皇星全音】【WAV+CUE】
- 林东松.1997-2039玫瑰事件【宝丽金】【WAV+CUE】