标签:
好久没来这里了。。记录下 最近整理的 一个小插件。并没有按照jquery 插件的模式来做。
以下是代码。就不详解了。逻辑很简单。有啥不明白的可以留言。
function loadCon (opts) { var count = 1, initTime = 800, //ms finishCount = 0, //totalCount = 100 perPercent = 0, perTime = 0, $count = null, $pie1 = null, $pie2 = null, limitCount = 0, percentVal = 1, timer = null; var loadHtml = ‘<div class="overlayLoadPPt">‘+ ‘ <div class="pie pie1" style="transform: rotate(0deg);"></div><div class="pie pie2" style="transform: rotate(-180deg);"></div>‘+ ‘ <div class="covert"><p class="count"></p> </div>‘+ //‘ <div class="covert"><img src="../img/loadingBG.png" style="width: 100%;"> </div>‘ ‘</div>‘; function buildHtml() { var $overlayLoadPPt = $(‘.overlayLoadPPt‘); $overlayLoadPPt.remove(); $(loadHtml).prependTo(‘body‘); $count = $(‘.overlayLoadPPt .count‘); $pie1 = $(‘.overlayLoadPPt .pie1‘); $pie2 = $(‘.overlayLoadPPt .pie2‘); beginLoading(); } function beginLoading() { var deg = parseInt(360/count); perTime = initTime/deg; limitCount = perPercent * percentVal; doTimer(); } this.updateChanges = function (val) { if(val >= count) { limitCount = 100; } else { percentVal = val; limitCount = perPercent * percentVal; } }; this.finishLoad = function () { perPercent = count; limitCount = 100; }; function doTimer() { timer = setTimeout(function () { clearTimeout(timer); timer = null; if(finishCount <= limitCount) { finishCount++; $count.html(finishCount+‘%‘); if(finishCount != 50) { $pie1.css(‘transform‘,‘rotate(‘+(finishCount*3.6+180)+‘deg)‘); } else { $pie2.css({‘background‘:‘#2e7418‘,‘width‘:‘160px‘,‘height‘:‘160px‘,‘transform‘:‘rotate(0deg)‘}); $pie1.css(‘transform‘,‘rotate(360deg)‘); } } if(finishCount >= 100) { clearTimeout(timer); timer = null; $count = null; $pie1 = null; $pie2 = null; } else { doTimer(); } },perTime); } function init() { count = opts.count; initTime = opts.initTime ? opts.initTime : initTime; perPercent = parseInt(100/count); buildHtml(); } init(); }; loadCon.prototype = { setPecent: function (val) { this.updateChanges(val); }, setEnd: function () { this.finishLoad(); } };
这个是js部分。以下是CSS部分
.overlayLoadPPt { position: absolute; top:0; left: 0; width: 100%; height: 100%; z-index: 9999999; background: #FFF; opacity: 1; } .pie { position: absolute; width: 160px; height: 160px; border-radius: 150px; background: #2e7418; clip: rect(0px,80px,160px,0px); left: 50%; top: 30%; margin: -80px; } .pie2 { z-index: 9999; background: #FFF; width: 161px; height: 161px; } .pie1 { z-index: 999; } .count { position: absolute; top: 65%; text-align: center; width: 100%; color: #FFF; } .covert { background: #57b243; position: absolute;z-index: 999999; width: 150px; height: 150px; border-radius: 340px; left: 50%; top: 30%; margin: -75px; overflow: hidden; }
调用也很简单。确保引入jquery。版本 应该还好。用最新的就好了
var load = new loadCon({count:5}); count:就是当前进度条分成几段来加载。 方法:setPecent 改变状态 load.setPecent(3) setEnd 告诉插件可以结束了
标签:
原文地址:http://www.cnblogs.com/blueSkys/p/4703901.html