DDR爱好者之家 Design By 杰米
本文实例讲述了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程序设计有所帮助。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年12月27日
2024年12月27日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]