javascript+css實(shí)現(xiàn)進(jìn)度條效果
本文實(shí)例為大家分享了javascript+css實(shí)現(xiàn)進(jìn)度條效果的具體代碼,供大家參考,具體內(nèi)容如下
主要是以樣式實(shí)現(xiàn)進(jìn)度條的效果,JavaScript控制顯示的百分比
html模板
<div class="progress_area"> <span id="progress" class="progress_bac"></span> </div> <input type="button" class="progress-inp" value="100%" οnclick="progress(100);"/> <input type="button" class="progress-inp" value="86%" οnclick="progress(86);" /> <input type="button" class="progress-inp" value="20%" οnclick="progress(20);"/>
css:
.progress_area{ width: 255px; height: 13px; border: 1px solid #ccc; border-radius: 15px; margin-bottom: 30px; } .progress-inp{ width: 60px; height: 28px; border: 1px solid #ccc; background: #62c7ef; border-radius: 8px; color: white; cursor: pointer; outline:none; } .progress_bac{ display: block; height: 100%; width: 50%; background: #83a4f1; border-radius: 10px; }
實(shí)現(xiàn)的效果:
感覺(jué)這個(gè)進(jìn)度條顯示的特別生硬;之后通過(guò)box-shadow對(duì)它加了個(gè)陰影效果:
box-shadow有6個(gè)參數(shù):
box-shadow:inset x-offset y-offset blur-radius spread-radius color
分別為:投影方式 X軸偏移量 Y軸偏移量 陰影模糊半徑 陰影擴(kuò)展半徑 陰影顏色
css:
.progress_bac{ display: block; height: 100%; width: 50%; background: #83a4f1; border-radius: 10px; -moz-box-shadow:0px 0px 7px 0px #4486ca; -webkit-box-shadow:0px 0px 7px 0px #4486ca; box-shadow:0px 0px 7px 0px #4486ca; }
效果:
陰影的顏色可以自定義,通過(guò)box-shadow可以實(shí)現(xiàn)高亮的效果,多多嘗試;
在點(diǎn)擊下方按鈕的時(shí)候,進(jìn)度條會(huì)顯示對(duì)應(yīng)的值,到指定的位置,但是通過(guò)之上的代碼來(lái)看,當(dāng)點(diǎn)擊按鈕的時(shí)候進(jìn)度條是一下子就到了指定的位置,沒(méi)有過(guò)度的效果;
通過(guò)javascript和css兩種方式來(lái)實(shí)現(xiàn):
css:
css來(lái)實(shí)現(xiàn)很簡(jiǎn)單,css中有個(gè)參數(shù)叫transition動(dòng)畫效果,通過(guò)改變改參數(shù)的寬度的動(dòng)畫效果,很簡(jiǎn)單的就實(shí)現(xiàn)出來(lái)
.progress_bac{ display: block; height: 100%; width: 50%; background: #83a4f1; border-radius: 10px; -moz-box-shadow:0px 0px 7px 0px #4486ca; -webkit-box-shadow:0px 0px 7px 0px #4486ca; box-shadow:0px 0px 7px 0px #4486ca; -moz-transition: width 0.5s; -webkit-transition: width 0.5s; transition: width 0.5s; }
javascript:
js實(shí)現(xiàn)的方式就有多種了可以寫個(gè)循環(huán)可以寫個(gè)定時(shí)器:以下代碼就是用定時(shí)器寫的;
function progress(value){ if ( value ){ var num = ""; var loader_progress = setInterval(function(){ num++; document.getElementById("progress").style.width = num+"%"; if ( num == value ){ clearInterval(loader_progress); } },10); } };
以上是簡(jiǎn)單的實(shí)現(xiàn)進(jìn)度條方式;修改css可以使進(jìn)度條展示不同的效果,這就需要一點(diǎn)點(diǎn)的調(diào)了;
相關(guān)文章
JavaScript實(shí)現(xiàn)擦玻璃效果分析鼠標(biāo)移動(dòng)響應(yīng)時(shí)間粒度問(wèn)題
這篇文章主要為大家介紹了JavaScript實(shí)現(xiàn)擦玻璃效果分析鼠標(biāo)移動(dòng)響應(yīng)時(shí)間粒度問(wèn)題詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10javascript秒數(shù)倒計(jì)時(shí)自動(dòng)跳轉(zhuǎn)代碼
幾秒后跳轉(zhuǎn)功能,動(dòng)態(tài)生成按鈕并動(dòng)態(tài)生成8位隨機(jī)數(shù),2008-09-09百度Popup.js彈出框進(jìn)化版 拖拽小框架發(fā)布 兼容IE6/7/8,Firefox,Chrome
百度空間的彈出窗口和拖拽效果(也就是popup.js),代碼精簡(jiǎn),效果也很好,我們可以在很多大型網(wǎng)站上見(jiàn)到這種效果,在我的項(xiàng)目中也使用了該js。2010-04-04顏色選擇器 Color Picker,IE,Firefox,Opera,Safar
顏色選擇器 Color Picker,需要的朋友可以參考下。2010-11-11js實(shí)現(xiàn)獲取當(dāng)前時(shí)間是本月第幾周的方法
這篇文章主要介紹了js實(shí)現(xiàn)獲取當(dāng)前時(shí)間是本月第幾周的方法,涉及javascript針對(duì)日期及時(shí)間的相關(guān)操作技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-08-08