jQuery iScroll.js 移动端滚动条美化插件
更新时间:2016年02月25日 15:53:43 作者:starof
这篇文章主要介绍了jQuery iScroll.js 移动端滚动条美化插件的相关资料,需要的朋友可以参考下
= pos;
pos = pos - that.wrapperH;
page++;
}
if (that.maxScrollY%that.wrapperH) that.pagesY[that.pagesY.length] = that.maxScrollY - that.pagesY[that.pagesY.length-1] + that.pagesY[that.pagesY.length-1];
}
// Prepare the scrollbars
that._scrollbar('h');
that._scrollbar('v');
if (!that.zoomed) {
that.scroller.style[transitionDuration] = '0';
that._resetPos(400);
}
},
scrollTo: function (x, y, time, relative) {
var that = this,
step = x,
i, l;
that.stop();
if (!step.length) step = [{ x: x, y: y, time: time, relative: relative }];
for (i=0, l=step.length; i<l; i++) {
if (step[i].relative) { step[i].x = that.x - step[i].x; step[i].y = that.y - step[i].y; }
that.steps.push({ x: step[i].x, y: step[i].y, time: step[i].time || 0 });
}
that._startAni();
},
scrollToElement: function (el, time) {
var that = this, pos;
el = el.nodeType ? el : that.scroller.querySelector(el);
if (!el) return;
pos = that._offset(el);
pos.left += that.wrapperOffsetLeft;
pos.top += that.wrapperOffsetTop;
pos.left = pos.left > 0 ? 0 : pos.left < that.maxScrollX ? that.maxScrollX : pos.left;
pos.top = pos.top > that.minScrollY ? that.minScrollY : pos.top < that.maxScrollY ? that.maxScrollY : pos.top;
time = time === undefined ? m.max(m.abs(pos.left)*2, m.abs(pos.top)*2) : time;
that.scrollTo(pos.left, pos.top, time);
},
scrollToPage: function (pageX, pageY, time) {
var that = this, x, y;
time = time === undefined ? 400 : time;
if (that.options.onScrollStart) that.options.onScrollStart.call(that);
if (that.options.snap) {
pageX = pageX == 'next' ? that.currPageX+1 : pageX == 'prev' ? that.currPageX-1 : pageX;
pageY = pageY == 'next' ? that.currPageY+1 : pageY == 'prev' ? that.currPageY-1 : pageY;
pageX = pageX < 0 ? 0 : pageX > that.pagesX.length-1 ? that.pagesX.length-1 : pageX;
pageY = pageY < 0 ? 0 : pageY > that.pagesY.length-1 ? that.pagesY.length-1 : pageY;
that.currPageX = pageX;
that.currPageY = pageY;
x = that.pagesX[pageX];
y = that.pagesY[pageY];
} else {
x = -that.wrapperW * pageX;
y = -that.wrapperH * pageY;
if (x < that.maxScrollX) x = that.maxScrollX;
if (y < that.maxScrollY) y = that.maxScrollY;
}
that.scrollTo(x, y, time);
},
disable: function () {
this.stop();
this._resetPos(0);
this.enabled = false;
// If disabled after touchstart we make sure that there are no left over events
this._unbind(MOVE_EV, window);
this._unbind(END_EV, window);
this._unbind(CANCEL_EV, window);
},
enable: function () {
this.enabled = true;
},
stop: function () {
if (this.options.useTransition) this._unbind(TRNEND_EV);
else cancelFrame(this.aniTime);
this.steps = [];
this.moved = false;
this.animating = false;
},
zoom: function (x, y, scale, time) {
var that = this,
relScale = scale / that.scale;
if (!that.options.useTransform) return;
that.zoomed = true;
time = time === undefined ? 200 : time;
x = x - that.wrapperOffsetLeft - that.x;
y = y - that.wrapperOffsetTop - that.y;
that.x = x - x * relScale + that.x;
that.y = y - y * relScale + that.y;
that.scale = scale;
that.refresh();
that.x = that.x > 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x;
that.y = that.y > that.minScrollY ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y;
that.scroller.style[transitionDuration] = time + 'ms';
that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px) scale(' + scale + ')' + translateZ;
that.zoomed = false;
},
isReady: function () {
return !this.moved && !this.zoomed && !this.animating;
}
};
function prefixStyle (style) {
if ( vendor === '' ) return style;
style = style.charAt(0).toUpperCase() + style.substr(1);
return vendor + style;
}
dummyStyle = null; // for the sake of it
if (typeof exports !== 'undefined') exports.iScroll = iScroll;
else window.iScroll = iScroll;
})(window, document);
html
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1, minimum-scale=1, maximum-scale=1" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <meta name="format-detection"content="telephone=no, email=no" /> <meta name="misapplication-tap-highlight" content="no"/> <meta name="HandheldFriendly" content="true"/> <meta name="screen-orientation" content="portrait"> <meta name="x5-orientation" content="portrait"> <meta name="msapplication-tap-highlight" content="no" /> <title></title> <link rel="stylesheet" type="text/css" href="css/tc.css"> <link rel="stylesheet" type="text/css" href="css/scrollbar.css"> <style> </style> </head> <body> <!--分配获奖号码--> <div class="tcbox" > <div class="tcmain"> <div class="tc_close"></div> <div class="tc-content01"> <div class="top-wrap"> <p>您成功参与了<strong>第<span>20151225001</span>期</strong>夺宝,参与<span class="col-org">10</span>人次。</p> <p>您成功参与了<strong>第<span>20151225002</span>期</strong>夺宝,参与<span class="col-org">10</span>人次。</p> </div> <p class="wish">您获得了<span class="col-org">20</span>个幸运号码,祝您夺宝成功!</p> <div id="tc-wrapper1"> <dl class="num-list"> <dt>第20151225001期</dt> <dd><span>10002351</span>,<span>10001384</span>,<span>10006354</span>,<span>10002634</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span></dd> <dt>第20151225002期</dt> <dd><span>10002351</span>,<span>10001384</span>,<span>10006354</span>,<span>10002634</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span></dd> </dl> </div> <div class="bottom-wrap"> <a href="javascript:;" class="tc-button" style="display:none">填写领奖地址</a> <a href="javascript:;" class="tc-button">确 定</a> </div> </div> </div> </div> <!--我的夺宝号码--> <div class="tcbox" style="display:none;"> <div class="tcmain"> <div class="tc_close"></div> <div class="tc-content02"> <p class="mynum">我的夺宝号码</p> <div id="tc-wrapper2"> <dl class="num-list"> <dd><span>10002351</span>,<span>10001384</span>,<span>10006354</span>,<span>10002634</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001384</span>,<span>10006354</span>,<span>10002634</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001384</span>,<span>10006354</span>,<span>10002634</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001384</span>,<span>10001384</span>,<span>10006354</span>,<span>10002634</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001384</span>,<span>10001384</span>,<span>10006354</span>,<span>10002634</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span>,<span>10001524</span>,<span>10002351</span>,<span>10001384</span></dd> </dl> </div> <div class="bottom-wrap"> <a href="javascript:;" class="tc-button">确 定</a> </div> </div> </div> </div> <!--我想参与人次--> <div class="tcbox" style="display:none;"> <div class="tcmain"> <div class="tc_close"></div> <div class="tc-content03"> <p class="buytext">我想参与人次</p> <div class="w-number-wrap"> <div class="w-number"> <input class="w-number-input" value="10"> <a class="w-number-btn w-number-btn-plus " data-pro="plus" href="javascript:void(0);">+</a> <a class="w-number-btn w-number-btn-minus w-number-btn-disabled" data-pro="minus" href="javascript:void(0);">-</a> </div> <span class="m-detail-main-buyHint"> <i class="ico-arrow"></i> <b>获奖概率<span>0.026%</span></b> <b style="display:none;">加大参与人次,夺宝在望!</b> </span> </div> <div class="bottom-wrap"> <a href="javascript:;" class="tc-button">确 定</a> </div> </div> </div> </div> <script type="text/javascript" src="js/iScroll.js"></script> <script type="text/javascript"> var myScroll1,myScroll2; function loaded() { myScroll1 = new iScroll('tc-wrapper1', { scrollbarClass: 'myScrollbar' , hScrollbar:false, vScroll:true, hideScrollbar: false //是否隐藏滚动条 }); myScroll2 = new iScroll('tc-wrapper2', { scrollbarClass: 'myScrollbar' , hScrollbar:false, vScroll:true, hideScrollbar: false //是否隐藏滚动条 }); } document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); document.addEventListener('DOMContentLoaded', loaded, false); /*显示弹层层调用show方法时重新调用new iScroll()*/ </script> </body> </html>
2、css
tc.css
@charset "utf-8"; body,div,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,code,form,fieldset,legend,button,textarea,table,tbody,tfoot,thead,th,td,article,aside,dialog,figure,footer,header,hgroup,menu,nav,section,time,mark,audio,video{margin:0;padding:0;outline:0;background:transparent;}article,aside,dialog,figure,footer,header,hgroup,nav,section{display:block;}body,button,input,select,textarea{font:12px/1.5 arial,\5b8b\4f53,sans-serif;}h1,h2,h3,h4,h5,h6,button,input,select,textarea{font-size:100%;outline:none;font-family:inherit}address,cite,dfn,em,var{font-style:normal;}code,kbd,pre,samp{font-family:courier new,courier,monospace;}small{font-size:12px;}ul,ol,li{list-style:none;}img{border:none;}a{text-decoration:none;outline:thin none;}a:hover{text-decoration:underline;}table{border-collapse:collapse;border-spacing:0;}.clear{clear:both;}.clearfix:after{visibility:hidden;display:block;font-size:0;content:" ";clear:both;height:0;}html{-webkit-text-size-adjust: none;} body{font:12px/1.5 \5FAE\8F6F\96C5\9ED1,tahoma,arial,\5b8b\4f53,sans-serif;} /*弹框*/ .tcbox{width:100%; height:100%; position:fixed; top:0; left:0; background:rgba(0,0,0,0.5); z-index:999; display:-webkit-box; -webkit-box-orient:horizontal; -webkit-box-pack:center; -webkit-box-align:center; display:-moz-box; -moz-box-orient:horizontal; -moz-box-pack:center; -moz-box-align:center; display:-o-box; -o-box-orient:horizontal; -o-box-pack:center; -o-box-align:center; display:-ms-box; -ms-box-orient:horizontal; -ms-box-pack:center; -ms-box-align:center; display:box; box-orient:horizontal; box-pack:center; box-align:center;} .col-org{color:#ff6200;} .tcmain{width:78%; max-width:580px; margin:0 auto; background:#fff;border-radius:5px; position:relative; box-sizing:border-box;text-align:center;} .tc_close{width:19px;height:19px;background: url(../images/tc_close.png) no-repeat;background-size:200%;overflow:hidden;position:absolute;right:8px;top:8px;cursor:pointer;} .tc_close:hover{background-position:100% 0;} .tcmain h1{font-size:1.4rem;} .tcmain a{display:block;} /*滚动条*/ #tc-wrapper1{ height: 146px; position: relative;width:84%;margin:0 auto; } #tc-wrapper2{ height: 146px; position: relative;width:84%;margin:0 auto; } /*公用按钮样式*/ .tcmain .bottom-wrap{margin-top:10px;background-color:#f2f2f2;border-radius:0 0 5px 5px;padding:10px 0;} .tcmain .tc-button{display:inline-block;margin:0 auto;min-width:100px;font-size:17px;padding:8px 15px;background-color:#da2b20;color:#fff;border-radius:5px;} .tcmain .tc-button:hover{text-decoration:none;} /*分配夺宝号码*/ .tc-content01 .top-wrap{font-size:0.75rem;color:#4d4d4d;text-align:left;padding:32px 8% 0;border-bottom:1px dotted #999;} .tc-content01 .top-wrap p{padding-bottom:0.5rem;} .tc-content01 .p-title{font-size:14px;padding-left:42px;} .tc-content01 .p-title.strong{padding-top:13px;} .tc-content01 .p-title span{color:#ff6200;} .tc-content01 .wish{font-size:0.75rem;color:#4d4d4d;padding:0.8rem 8% 1rem;text-align:left;} .tc-content01 .num-list{text-align:left;} .tc-content01 .num-list dt{font-size:0.625rem;color:#1a1a1a;padding-bottom:4px;} .tc-content01 .num-list dd{font-size:0.625rem;color:#808080;padding-bottom:20px;word-wrap:break-word;} .tc-content01 .num-list dd span{display:inline-block;white-space:nowrap;} /*全部号码*/ .tc-content02 .mynum{padding:25px 0 12px;font-size:0.75rem;color:#404040;} .tc-content02 .num-list{text-align:left;} .tc-content02 .num-list dd{font-size:0.625rem;line-height:1.5rem;color:#333;padding-bottom:20px;word-wrap:break-word;} .tc-content02 .num-list dd span{display:inline-block;white-space:nowrap;} /*参与人次*/ .tc-content03 .buytext{padding:30px 0 12px;font-size:0.8125rem;color:#404040;} .tc-content03 .w-number-wrap{position:relative;padding-bottom:25px;} .tc-content03 .w-number { position: relative; margin:0 auto; height:45px; width:88px; vertical-align: middle; padding:0 35px; } .tc-content03 .w-number-input { float: left; font-size:20px; text-align: center; width: 78px; border: 1px solid #dadada; background-color:#fafafa; height: 44px; line-height:44px; padding: 0 4px; outline: medium none; } .tc-content03 .w-number-btn { color:#666; border: 1px solid #E0E0E0; position: absolute; font-size:20px; text-align: center; text-decoration: none; width: 34px; height: 44px; line-height: 44px; overflow: hidden; font-weight:700; } .tc-content03 .w-number-btn:hover{color:#da2b20;text-decoration:none;} .tc-content03 .w-number-btn-plus { right: 0px; top: 0px; } .tc-content03 .w-number-btn-minus { right: auto; left: 0px; top: 0px; } /*中奖概率*/ .tc-content03 .m-detail-main-buyHint { position: absolute; left:100px; top:50px; font-size:0.625rem; padding: 0px 8px 0px 8px; display: inline-block; background-color: #ffe3e3; border: 1px solid #e0e0e0; color: #fe7386; line-height:1rem; border-radius: 4px; } .tc-content03 .m-detail-main-buyHint b { font-weight: normal; } .tc-content03 .m-detail-main-buyHint .ico-arrow { position: absolute; left: 40px; top:-4px; width:6px; height:4px; background: url(../images/tip-top.png) no-repeat center; background-size:100%; overflow: hidden; }
scrollbar.css
@charset "utf-8"; /* CSS Document */ /** * * Horizontal Scrollbar * */ .myScrollbarH { position:absolute; z-index:100; height:8px; bottom:1px; left:2px; right:7px } .myScrollbarH > div { position:absolute; z-index:100; height:100%; /* The following is probably what you want to customize */ background-image:-webkit-gradient(linear, 0 0, 100% 0, from(#a00), to(#f00)); background-image:-moz-linear-gradient(top, #f00, #900); background-image:-o-linear-gradient(top, #f00, #900); border:1px solid #900; -webkit-background-clip:padding-box; -moz-background-clip:padding-box; -o-background-clip:padding-box; background-clip:padding-box; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; -o-box-sizing:border-box; box-sizing:border-box; -webkit-border-radius:4px; -moz-border-radius:4px; -o-border-radius:4px; border-radius:4px; -webkit-box-shadow:inset 1px 1px 0 rgba(255,255,255,0.5); -moz-box-shadow:inset 1px 1px 0 rgba(255,255,255,0.5); -o-box-shadow:inset 1px 1px 0 rgba(255,255,255,0.5); box-shadow:inset 1px 1px 0 rgba(255,255,255,0.5); } /** * * Vertical Scrollbar * */ .myScrollbarV { position:absolute; z-index:100; width:4px;bottom:7px;top:2px;right:1px; background-color:#d6d6d6; border-radius:4px; } .myScrollbarV > div { position:absolute; z-index:100; width:100%; /* The following is probably what you want to customize */ background:-webkit-gradient(linear, 0 0, 100% 0, from(#f00), to(#ff6200)); background-image:-moz-linear-gradient(top, #f00, #ff6200); background-image:-o-linear-gradient(top, #f00, #ff6200); border:1px solid #ff6200; -webkit-background-clip:padding-box; -moz-background-clip:padding-box; -o-background-clip:padding-box; background-clip:padding-box; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; -o-box-sizing:border-box; box-sizing:border-box; -webkit-border-radius:4px; -moz-border-radius:4px; -o-border-radius:4px; border-radius:4px; -webkit-box-shadow:inset 1px 1px 0 rgba(255,255,255,0.5); -moz-box-shadow:inset 1px 1px 0 rgba(255,255,255,0.5); -o-box-shadow:inset 1px 1px 0 rgba(255,255,255,0.5); box-shadow:inset 1px 1px 0 rgba(255,255,255,0.5); }
3、效果
您可能感兴趣的文章:
- jQuery中Nicescroll滚动条插件的用法
- jquery插件jquery.nicescroll实现图片无滚动条左右拖拽的方法
- jQuery niceScroll滚动条错位问题的解决方法
- jquery滚动条插件jScrollPane的使用介绍
- jQuery滚动条插件nanoscroller使用指南
- 学习使用jquery iScroll.js移动端滚动条插件
- jquery滚动条插件slimScroll使用方法
- jquery自定义滚动条插件示例分享
- jquery滚动条插件(可以自定义)
- jQuery leonaScroll 1.1 自定义滚动条插件(推荐)
- jQuery滚动条美化插件nicescroll简单用法示例
最新评论