2012/11/9 15:57:32作者:佚名來源:網絡
【實例名稱】
用CSS+JS制作進度條(二)
【實例描述】
本例學習如何使用CSS+JavaScript的方式實現常見的進度條。
【實例代碼】
<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>標題頁-學無憂(www.yzddtk.cn)</title> </head> <body> <style type="text/css"> #divLoadCont{position:absolute; z-index:500; left:0; top:0; width:100%; height:98%; clip:rect(0,100%,100%,0); background-color:white; layer-background-color:white; } #divLoad1{position:absolute; layer-background-color:silver; background-color:silver} #divLoad2{position:absolute; left:0; top:0; layer-background-color:navy; background-color:navy} #divLoadText{position:absolute; background-color:transparent; font-family:arial,helvetica; color:Navy; font-size:14px; } </style> <script language="JavaScript" type="text/javascript"> function pro_bwcheck(){ //檢測瀏覽器的代碼-通用 this.ver=navigator.appVersion this.agent=navigator.userAgent this.dom=document.getElementById?1:0 this.opera5=this.agent.indexOf("Opera 5")>-1 this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0; this.ie4=(document.all && !this.dom && !this.opera5)?1:0; this.ie=this.ie4||this.ie5||this.ie6 this.mac=this.agent.indexOf("Mac")>-1 this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; this.ns4=(document.layers && !this.dom)?1:0; this.bw=(this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5) return this } var bw=new pro_bwcheck() numImages=12 //默認10個圖片 loaderWidth=350 //設置進度條的寬度 currentImg=0 function pro_doc_size(){ //判斷顯示區域 this.x=0;this.x2=bw.ie && document.body.offsetWidth-20||innerWidth||0; this.y=0;this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0; if(!this.x2||!this.y2) return message('窗體的寬度和高度不夠!') this.x50=this.x2/2;this.y50=this.y2/2; return this; } function pro_obj(obj,nest){ //定義頁面中承載進度條的控件屬性 nest=(!nest) ? "":'document.'+nest+'.' this.evnt=bw.dom? document.getElementById(obj): bw.ie4?document.all[obj]:bw.ns4?eval (nest+"document.layers." +obj):0; this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt; this.ref=this.css this.w=this.evnt.offsetWidth||this.css.clip.width|| this.ref.width||this.css.pixelWidth||0; return this } pro_obj.prototype.moveIt = function(x,y){ //定義移動方法 this.x=x;this.y=y; this.css.left=x;this.css.top=y } pro_obj.prototype.clipTo = function(t,r,b,l,setwidth){ //重新定義裁剪方法 this.ct=t; this.cr=r; this.cb=b; this.cl=l if(bw.ns4){ this.css.clip.top=t;this.css.clip.right=r this.css.clip.bottom=b;this.css.clip.left=l }else{ if(t<0)t=0;if(r<0)r=0;if(b<0)b=0;if(b<0)b=0 this.css.clip="rect("+t+","+r+","+b+","+l+")"; if(setwidth){this.css.pixelWidth=this.css.width=r; this.css.pixelHeight=this.css.height=b} } } var oLoad2 function startLoading(){ page=new pro_doc_size() //以下設置加載控件的一些基本屬性 oLoadCont=new pro_obj('divLoadCont') oLoad=new pro_obj('divLoad1','divLoadCont') oLoad2=new pro_obj('divLoad2',' divLoadCont.document.divLoad1') oLoadText=new pro_obj('divLoadText', 'divLoadCont.document.divLoad1') oLoad.moveIt(page.x50-loaderWidth/2,page.y50-20) oLoadText.moveIt(loaderWidth/2 - oLoadText.w/2,10) oLoad.clipTo(0,loaderWidth,40,0,1) //裁剪區域 oLoad2.per = loaderWidth/numImages //百分比 } function loadIt_display(ok){ currentImg++ if(oLoad2) oLoad2.clipTo(0,oLoad2.per*currentImg,40,0,1) //裁剪顯示的區域 if(currentImg<=numImages) setTimeout("loadIt_display(1)",200) //使用定時器不斷加載圖片 else{ oLoadCont.css.visibility='hidden' //進度條加載完成后隱藏 } } </script> <div id="divLoadCont"> <div id="divLoad1"> <div id="divLoad2"></div><br> <div id="divLoadText">頁面加載中,請稍候...</div> </div> </div> <script> startLoading() loadIt_display(1) </script> </body> </html>
【運行效果】
【難點剖析】
本例的重點在于樣式表中div層的布局。樣式表設置div的背景色和邊框顏色為藍色,然后使用JavaScript計算進度條的寬度和每次顯示的進度,其中重點是“clipTo”方法。本例重新定義了此方法,目的是實現一個矩形塊狀區域的顯示。
【源碼下載】
為了JS代碼的準確性,請點擊:用CSS+JS制作進度條(二) 進行本實例源碼下載
標簽: 進度條
相關文章
ip雷達 v5.0.2綠色版
詳情WinSCPv5.15.1綠色中文版
詳情filezilla client v5.5
詳情wireshark中文版 v3.4.9
詳情Boson Netsimv10.8破解版
詳情風行播放器 v3.0.6.106
詳情愛奇藝客戶端 v10.1.0.6636官方版
詳情搜狐影音 v7.0.19.0官方版
詳情樂視視頻 v7.3.2.192
詳情華數tv客戶端PC版 v1.1.2.0
詳情cbox央視影音 v5.1.2.1經典版
詳情軟媒收音機(魔方) v1.13
詳情傾聽網絡收音機 v3.0.0.0
詳情魅影流聲全球網絡收音機 v1.0.0.1
詳情酷狗電臺 v8.2.75
詳情暴龍網絡收音機 v2.5.1
詳情克莉2v1.0中文版
詳情冬日計劃v1.2中文版
詳情刺客信條英靈殿v1.0吾愛破解版
詳情刺客信條英靈殿終極v1.0免安裝破解版
詳情動物森友會v1.10.0最新破解版
詳情哈迪斯殺出地獄v1.37中文破解版
詳情嗜血印中文豪華版v1.0豪華版破解版 附游戲攻略秘籍
詳情城市戰斗v1.0中文破解版
詳情尼爾人工生命v1.0steam免費破解版
詳情尼爾人工生命升級版v1.0PC破解版
詳情尼爾人工生命升級版v1.2247中文破解版
詳情層層恐懼2中文破解版v1.0綠色免安裝版
詳情往日不再v1.0 steam破解版
詳情往日不再v1.0pc破解版
詳情救贖之路v1.0中文破解版
詳情斯蓋爾女仆v1.0中文破解版
詳情新盜墓筆記官方版v1.215.589730
詳情無盡的拉格朗日無限金幣鉆石版v1.2.267172破解版
詳情明日之后無限小太陽版v1.0.246安卓版
詳情雙生幻想vivo版v6.6.83安卓版
詳情劍網1歸來內購免費版v1.1.116安卓版
詳情模擬城市我是市長國際版v0.69.21342.22832安卓版
詳情迷你世界999999迷你幣版v1.20.5破解版
詳情王牌戰爭無限內購版v9.7安卓版
詳情云上城之歌不氪金版v10.16安卓版
詳情王鏟鏟的致富之路破解版v1.1.8安卓版
詳情創造與魔法無限點券版v1.0.0505安卓版
詳情狩獵使命九游版v1.6.6.000
詳情魔鏡物語變態版v2.1.4無限金幣版
詳情黑月手游免費版v2.2.0安卓版
詳情曙光英雄v1.0.12.0.20無限鉆石版
詳情原始傳奇無限元寶版v1.6.806內購破解版
詳情