jquery 步驟進(jìn)度軸插件的實(shí)現(xiàn)代碼
每天一個(gè)jquery插件-步驟進(jìn)度軸 步驟進(jìn)度軸
很多工具型的網(wǎng)站入門教程或者注冊(cè)賬號(hào)走流程的時(shí)候會(huì)有這個(gè)結(jié)構(gòu)存在,所以做了一個(gè)來嘗試一下,回調(diào)動(dòng)作也能用吧
效果如下
代碼部分
*{ margin: 0; padding: 0; } #div{ width: 90%; height: 50px; margin: 10px auto; display: flex; justify-content: center; align-items: center; } #box{ width: 90%; height: 100px; border: 1px solid lightgray; margin: 10px auto; display: flex; justify-content: center; align-items: center; position: relative; } .box{ position: absolute; width: 100%; height: 100%; top: 0; left: 0; display: flex; justify-content: center; align-items: center; background-color: black; color: white; } .tbar{ width: 90%; height: 6px; border-radius: 5px; background-color: lightgray; display: flex; align-items: center; position: absolute; } .bar{ width: 100%; height: 50%; border-radius: 5px; background-color: #1abc9c; transition: all 0.2s linear; } .dot{ position: absolute; width: 12px; height: 12px; border-radius: 50%; background-color: lightgray; cursor: pointer; display: flex; justify-content: center; align-items: center; } .dot:hover{ transition: all 0.5s linear; background-color: #1abc9c; } .dot.check{ background-color: #1abc9c; } .dot .txt{ top: 100%; font-size: 12px; position: absolute; width: 100px; text-align: center; }
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>步驟進(jìn)度軸</title> <script src="js/jquery-3.4.1.min.js"></script> <script src="js/bzjdz.js"></script> <link href="css/bzjdz.css" rel="external nofollow" rel="stylesheet" type="text/css" /> </head> <body> <div id="div"> </div> <div id="box"> <div class="box" id="box1" style="background-color: #1abc9c;">步驟1</div> <div class="box" id="box2" style="background-color: #3498db;">步驟2</div> <div class="box" id="box3" style="background-color: #f1c40f;">步驟3</div> <div class="box" id="box4" style="background-color: #e74c3c;">步驟4</div> <div class="box" id="box5" style="background-color: #9b59b6;">步驟5</div> </div> </body> </html> <script> $(function(){ $("#div").timeline({ data:[ {name:'步驟1',id:'#box1',click:hide}, {name:'步驟2',id:'#box2',click:hide}, {name:'步驟3',id:'#box3',click:hide}, {name:'步驟4',id:'#box4',click:hide}, {name:'步驟5',id:'#box4',click:hide}, ] }) }) function hide(item){ $(".box").hide(); $(item.id).show(); } </script>
$.prototype.timeline =function(op){ console.log(op.data); var $that = $(this); var $tbar =$("<div class='tbar'></div>"); var $bar =$("<div class='bar'></div>"); $bar.appendTo($tbar) $tbar.appendTo($that); var length = op.data.length;//元素長度 var index = 0;//當(dāng)前進(jìn)行到哪個(gè)步驟 op.data.forEach((item,index)=>{ var per = getper(index,length) var $dot = $("<div class='dot' data-index='"+index+"'><div class='txt'>"+item.name+"</div></div>"); $dot.appendTo($tbar); $dot.css('left',"calc("+per+"% - 6px)") }) //點(diǎn)擊事件 $that.find('.dot').click(function(){ index = parseInt($(this).attr('data-index')); //執(zhí)行對(duì)應(yīng)的方法 click(); }) click(); function click(){ //回調(diào) var item = op.data[index]; item.click(item); //動(dòng)畫樣式 var per = getper(index,length) $bar.css('width',per+'%') //按鈕選中的控制 op.data.forEach((item,i)=>{ if(i<=index){ $tbar.find(".dot[data-index='"+i+"']").addClass('check'); }else{ $tbar.find(".dot[data-index='"+i+"']").removeClass('check'); } }) } function getper(i,l){ var temp = 0; if(i!=0&&i!=l-1){ temp = i/(l-1)*100//算出大概的距離 }else if(i==l-1){ temp = 100 } return temp; } }
思路解釋
要做的內(nèi)容很簡單,畫出時(shí)間軸,標(biāo)記對(duì)應(yīng)的點(diǎn),然后在觸發(fā)對(duì)應(yīng)事件的時(shí)候正確調(diào)用回調(diào)
時(shí)間軸畫的時(shí)候就那樣,百分比一填滿就沒啥了,然后里面把會(huì)變化進(jìn)度的和校園點(diǎn)分開繪制
小圓點(diǎn)點(diǎn)擊的時(shí)候改變當(dāng)前結(jié)構(gòu)標(biāo)記,然后觸發(fā)一個(gè)事件,把動(dòng)畫效果和回調(diào)一并執(zhí)行、
完事,休息
以上就是jquery 步驟進(jìn)度軸插件的實(shí)現(xiàn)代碼的詳細(xì)內(nèi)容,更多關(guān)于jQuery步驟進(jìn)度軸的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Jquery實(shí)現(xiàn)列表(隔行換色,全選,鼠標(biāo)滑過當(dāng)前行)效果實(shí)例
Jquery實(shí)現(xiàn)列表(隔行換色,全選,鼠標(biāo)滑過當(dāng)前行)效果實(shí)例,需要的朋友可以參考一下2013-06-06jQuery插件zTree實(shí)現(xiàn)的多選樹效果示例
這篇文章主要介紹了jQuery插件zTree實(shí)現(xiàn)的多選樹效果,結(jié)合實(shí)例形式分析了jQuery樹形插件zTree實(shí)現(xiàn)多選樹效果的具體操作步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-03-03jquery mobile 實(shí)現(xiàn)自定義confirm確認(rèn)框效果的簡單實(shí)例
下面小編就為大家?guī)硪黄猨query mobile 實(shí)現(xiàn)自定義confirm確認(rèn)框效果的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06jQuery學(xué)習(xí)之prop和attr的區(qū)別示例介紹
prop和attr的區(qū)別你知道嗎?在本文有些不錯(cuò)的示例對(duì)兩者詳細(xì)介紹,感興趣的朋友不要錯(cuò)過2013-11-11jQuery修改li下的樣式以及l(fā)i下的img的src的值的方法
這篇文章主要為大家介紹了jQuery如何修改li下的樣式,以及修改li下的img的src的值,示例代碼很簡單,一看就會(huì)2014-11-11jquery實(shí)現(xiàn)圖片裁剪思路及實(shí)現(xiàn)
JS,jquery不能實(shí)現(xiàn)圖片的裁剪,只是顯示了一個(gè)假象,在服務(wù)器上用獲得的各個(gè)坐標(biāo)值,以及原始圖片,用JAVA進(jìn)行裁剪2013-08-08jQuery HTML css()方法與css類實(shí)例詳解
這篇文章主要介紹了jQuery HTML css()方法與css類,結(jié)合實(shí)例形式詳細(xì)分析了jQuery HTML css()方法與css類相關(guān)函數(shù)用法與操作注意事項(xiàng),需要的朋友可以參考下2020-05-05利用jQuery來動(dòng)態(tài)為屬性添加或者刪除屬性的簡單方法
下面小編就為大家?guī)硪黄胘Query來動(dòng)態(tài)為屬性添加或者刪除屬性的簡單方法。小編覺的挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12全面解析jQuery $(document).ready()和JavaScript onload事件
這篇文章主要介紹了全面解析jQuery $(document).ready()和JavaScript onload事件的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06