博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iScroll4插件的使用实例
阅读量:7098 次
发布时间:2019-06-28

本文共 10199 字,大约阅读时间需要 33 分钟。

iScroll是Matteo Spinelli开发的一个滚动插件,使用原生js编写,其不依赖与任何js框架。iScroll 4 完全重写了iScroll这个框架的原始代码。旨在解决移动webkit系浏览器的区域滚动问题,兼容mobile safari、android默认浏览器、safari、chrome、firefox5+、opera11+、IE9+及其他webkit核心浏览器。最新版本为iscroll4。 目前正在开发iscroll5还未发布。iscroll 4.2版本兼容:iPhone/Ipod touch >=3.1.1, iPad >=3.2, Android >=1.6, Desktop Webkit, Firefox, Opera desktop/mobile.

除了旧版本的iScroll的特性以外,iScroll 4还包括如下的特性:
     (1)缩放(Pinch/Zoom)
    (2)拉动刷新(Pull up/down to refresh)
    (3)速度和性能提升
    (4)精确捕捉元素
    (5)自定义滚动条

最近的项目需要一个iOS页面,这里就采用了iScroll4来实现。下面是项目实例代码:

html文档conlist.html源码

 

appweb
';//下拉加载数据loadAjax(url,data,function(json){if(json.statuscode == 2){if(pullcount==0){msgalert('已经全部加载!', 'UpLabel');pullcount =1;}$('#pullUp').hide();}else if(json.statuscode == 1){dataProcess(json,html,$el);}else{msgalert('加载数据出错了,请重试~', 'UpLabel');//$('#pullUp').hide();} myScroll.refresh();});}function loaded() {pullDownEl = document.getElementById('pullDown');pullDownOffset = pullDownEl.offsetHeight;pullUpEl = document.getElementById('pullUp');pullUpOffset = pullUpEl.offsetHeight;pullDownAction();var documentHeight = document.documentElement.clientHeight + 50;$('#thelist').css('min-height',documentHeight+'px');myScroll = new iScroll('wrapper', {topOffset:pullDownOffset,onRefresh: function () {if (pullDownEl.className.match('loading')) {pullDownEl.className = '';pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';} else if (pullUpEl.className.match('loading')) {pullUpEl.className = '';pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';}},onScrollMove: function () {if (this.y > 5 && !pullDownEl.className.match('flip')) {pullDownEl.className = 'flip';pullDownEl.querySelector('.pullDownLabel').innerHTML = '释放立即刷新...';this.minScrollY = 0;} else if (this.y < 5 && pullDownEl.className.match('flip')) {pullDownEl.className = '';pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';this.minScrollY = -pullDownOffset;} else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {pullUpEl.className = 'flip';pullUpEl.querySelector('.pullUpLabel').innerHTML = '释放立即刷新...';this.maxScrollY = this.maxScrollY;} else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {pullUpEl.className = '';pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';this.maxScrollY = pullUpOffset;}},onScrollEnd: function () {if (pullDownEl.className.match('flip')) {pullDownEl.className = 'loading';pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Loading...';pullDownAction();} else if (pullUpEl.className.match('flip')) {pullUpEl.className = 'loading';pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Loading...';pullUpAction();}}});setTimeout(function () { document.getElementById('wrapper').style.left = '0'; }, 800);}document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);
评论列表页面
全部评论
下拉刷新...
热带小水果
2013-07-17 12:28
不馈是TOP10,都是很棒的游戏,火线追击好爽啊~~推荐!
大海啊全都是水
2013-07-17 12:28
跑跑卡丁车的界面操作等与PC版类似,最让人惊讶的是赛车的操控性和反应度都十分灵敏。对新手,跑跑卡丁车会比其他手机赛车游戏更难以控制和把握。
热带小水果
2013-07-17 12:28
不馈是TOP10,都是很棒的游戏,火线追击好爽啊~~推荐!
热带小水果
2013-07-17 12:28
不馈是TOP10,都是很棒的游戏,火线追击好爽啊~~推荐!
愤怒的小鸟
2013-07-17 12:28
愤怒的小鸟愤怒的小鸟愤怒的小鸟愤怒的小鸟愤怒的小鸟~~推荐!
玩机宝典
2013-07-17 12:28
玩机宝典玩机宝典玩机宝典玩机宝典玩机宝典玩机宝典~~推荐!
热带小水果
2013-07-17 12:28
不馈是TOP10,都是很棒的游戏,火线追击好爽啊~~推荐!
大海啊全都是水
2013-07-17 12:28
跑跑卡丁车的界面操作等与PC版类似,最让人惊讶的是赛车的操控性和反应度都十分灵敏。对新手,跑跑卡丁车会比其他手机赛车游戏更难以控制和把握。
热带小水果
2013-07-17 12:28
不馈是TOP10,都是很棒的游戏,火线追击好爽啊~~推荐!
热带小水果
2013-07-17 12:28
不馈是TOP10,都是很棒的游戏,火线追击好爽啊~~推荐!
愤怒的小鸟
2013-07-17 12:28
愤怒的小鸟愤怒的小鸟愤怒的小鸟愤怒的小鸟愤怒的小鸟~~推荐!
玩机宝典
2013-07-17 12:28
玩机宝典玩机宝典玩机宝典玩机宝典玩机宝典玩机宝典~~推荐!
愤怒的小鸟
2013-07-17 12:28
愤怒的小鸟愤怒的小鸟愤怒的小鸟愤怒的小鸟愤怒的小鸟~~推荐!
玩机宝典
2013-07-17 12:28
玩机宝典玩机宝典玩机宝典玩机宝典玩机宝典玩机宝典~~推荐!
大海啊全都是水
2013-07-17 12:28
跑跑卡丁车的界面操作等与PC版类似,最让人惊讶的是赛车的操控性和反应度都十分灵敏。对新手,跑跑卡丁车会比其他手机赛车游戏更难以控制和把握。
热带小水果
2013-07-17 12:28
不馈是TOP10,都是很棒的游戏,火线追击好爽啊~~推荐!
热带小水果
2013-07-17 12:28
不馈是TOP10,都是很棒的游戏,火线追击好爽啊~~推荐!
愤怒的小鸟
2013-07-17 12:28
愤怒的小鸟愤怒的小鸟愤怒的小鸟愤怒的小鸟愤怒的小鸟~~推荐!
玩机宝典
2013-07-17 12:28
玩机宝典玩机宝典玩机宝典玩机宝典玩机宝典玩机宝典~~推荐!
大海啊全都是水
2013-07-17 12:28
跑跑卡丁车的界面操作等与PC版类似,最让人惊讶的是赛车的操控性和反应度都十分灵敏。对新手,跑跑卡丁车会比其他手机赛车游戏更难以控制和把握。
上拉加载更多...
 
对应CSS文件css.css:

 

 

@charset "utf-8";/*--------------------------------------------------------------------version:	1.0author:	cupbluelast update:	2013-07-18---------------------------------------------------------------------*//*reset*/html,body,div,h1,h2,h3,h4,h5,h6,p,span,em,cite,del,a,img,ul,li,ol,button,input,textarea,dl,dt,dd,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}ol,ul{list-style:none;}body{font:12px/1.5 Arial,Verdana,Lucida,Helvetica,simsun,sans-serif;text-align:left;color:#000;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}em{font-style:normal;}input{font-size:12px; color:#000;outer:none;outline:none;}table{border-collapse:collapse;border-spacing:0;border:0 none;}a{cursor:pointer;text-decoration:none;outline:none;color:#000;-webkit-transition:all .2s linear;transition:all .2s linear;-moz-transition:all .2s linear;-ms-transition:all .2s linear;-o-transition:all .2s linear;transition:all .2s linear;}button{cursor:pointer;}a:hover{text-decoration:underline;color:#000;}input, select, form img, button,label,textarea{font-size:12px;vertical-align:middle; font-family:Tahoma;color:#000;}/*global*/a.untransition{-webkit-transition:none;transition:none;-moz-transition:none;-ms-transition:none;-o-transition:none;transition:none}.clearfix{zoom:1;}.clearfix:after{content:"";display:block;height:0;line-height:0;clear:both;visibility:hidden;}/*article*/body{	font:14px/1.5 'Apple LiGothic Medium','Apple LiSung Light', 'Times New Roman', Times;	color: #333;}.wrapper {	width:100%;	margin:0 auto;}.content{	padding:25px 15px 10px;}.wrapper .tit{	text-align:center;	font-weight:900;	font-size:18px;	margin:10px auto;}.wrapper .subtit{	color:#787878;	font-size:12px;	text-align:center;	margin:10px auto;}.wrapper .subtit span{	margin-right:10px;}.wrapper p{	padding:5px 0;	text-indent:2em;	color:#333;}.wrapper p.img{	text-align:center;	margin:0 auto;	text-indent:0;}.wrapper .img img{	width:240px;	height:160px;	}.content .inner{	overflow:hidden;	height:480px;}.content .card{	background:#f3f3f3;	position:relative;	padding:10px 0;	margin:5px auto;}.content .card .moreabout{	position:absolute;	left:0;	top:0;	right:0;	bottom:0;}.content .flag{	position:absolute;	top:-8px;	left:5px;	background:url("../images/clip.png") no-repeat scroll 0 0 transparent;	width:17px;	height:19px;	background-size: 17px 19px;}.content .icon{	position:absolute;	top:10px;	left:20px;}.content .icon,.content .icon img{	width:72px;	height:72px;	overflow:hidden;}.content .info{	padding-left:100px;	min-height:72px;}.info .card-tit{	color:#333;	padding:5px 0;	font-size:15px;}.info .card-detail{	color:#666;	line-height:1.5;	padding-right:5px;	font-size:12px;}.info .card-detail span{	margin-right:10px;	word-wrap:break-word;	word-break:break-all;}.content .toggle{	color:#999;	text-align:center;	width:100%;	margin:10px auto;	font-size:12px;}.toggle i{	width:20%;	border-top:1px solid #e4e4e4;	display:inline-block;	margin:0 15px ;	vertical-align:middle;}.comment{	margin-bottom:10px;}.comment .combar{	height:25px;	line-height:25px;	border-bottom:2px solid #efefef;	position:absolute;	left:0;	top:0;	width:100%;	z-index:2;}.combar span, .combar a{	font-weight:900;	letter-spacing:1px;	font-size:13px;	padding:0 5px;}.combar .combar-tit{	position:absolute;	left:15px;	color:#333;	border-bottom:2px solid #ce0000;	outline:none;}.combar .combar-togg{	position:absolute;	right:0;	/*background:#ce0000;	padding:0 30px;*/	background:url("../images/tog.png") no-repeat scroll 0 0 transparent;	height:25px;	width:76px;	background-size:76px 25px;}.combar .combar-goto{	position:absolute;	right:0;	background:#ce0000;	padding:0 15px;	height:25px;	line-height:25px;	color:#fff;}.combar-togg > *{	display:inline-block;}.combar-togg span{	color:#fff;	}.combar-togg b{	width:23px;	height:23px;	background:url("../images/bg.png") no-repeat scroll -5px -58px transparent;}.combar-togg i{	width:14px;	height:14px;	background:url("../images/bg.png") no-repeat scroll -5px -102px transparent;}.comlist{	margin:5px auto;}.comitem{	position:relative;	//float:left;	//width:100%;	border-bottom:1px solid #eee;	min-height:40px;	padding:5px 10px;	//background-color:#FAFAFA;}.comitem .comitem-pic{	width:40px;	height:40px;	margin:5px 10px 5px 0px;	overflow:hidden;	float:left;	display:inline-block;}.comitem-pic img{	width:40px;	height:40px;	}.comitem .comitem-para{	display:inline-block;	/*width:78%;*/	width:100%;}.comitem .para-by{	color:#999;	font-size:12px;	padding:2px 0;}.comitem .para-by em{	margin-right:20px;}.comitem .para-con{	color:#444;	font-size:14px;}.border-btnone{	border-bottom:0;}.fixbar{	position:absolute;	bottom:0;	left:0;	height:50px;	width:100%;	z-index:2;}.fixbar > div{	padding:0 10px;}.fixbar .fixstretch{	position:absolute;	left:0;	right:0;	top:0;	bottom:0;	background-image:-moz-linear-gradient(center top , #fff, #343434);	background-image:-webkit-gradient(linear,left top,left bottom,color-stop(0,#fff),color-stop(1,#343434));	background-image:-o-linear-gradient(top, #fff, #343434);	opacity:0.3;}.fixbar a{	display:block;	width:40px;	height:40px;	background-color:#7f7f7f;	border-radius:25px;	position:absolute;	top:0;	cursor:pointer;	outline:none;}.fixbar a b{	display:block;	width:40px;	height:40px;}.fixbar a.ret{	left:15px;}.fixbar a.reply{	right:30px;}.fixbar a.ret b{	background:url("../images/back.png") no-repeat scroll center center transparent;	background-size:16px 16px;}.fixbar a.reply b{	background:url("../images/edit.png") no-repeat scroll center center transparent;	background-size:16px 16px;}
 

 

转载地址:http://rkhql.baihongyu.com/

你可能感兴趣的文章
.NET自动识别GB2312与UTF-8编码的文件
查看>>
Linux下apache日志分析与状态查看方法
查看>>
hdu2412(树形dp)
查看>>
js返回函数, 函数名后带多个括号的用法及join()的注意事项
查看>>
【NOIP2007】矩阵取数
查看>>
关于VIM在Win10下的无意义折腾
查看>>
ibatis example Class 使用
查看>>
android的触摸事件(转)
查看>>
springMVC与struts2的区别
查看>>
【DB2数据库在windows平台上的安装】
查看>>
课后作业-阅读任务-阅读笔记-4
查看>>
Yii2数据缓存详解
查看>>
02Scala-函数定义、流程控制、异常处理入门实战
查看>>
jquery,smarty,dedecms的插件思路------dede未实践
查看>>
php pdo错误:SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
查看>>
Team Foundation Server:CodeUI Automation Test 学习笔记4
查看>>
Linux 小知识翻译 - 「cron」
查看>>
docker 一些简略环境搭建及部分链接
查看>>
android studio获取SHA1
查看>>
怎么才能在windows使用git命令
查看>>