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;}