使用Ajax實(shí)現(xiàn)進(jìn)度條的繪制
使用:easy mock創(chuàng)建api接口
注意:若彈出該invalid or unexpected token錯(cuò)誤提示信息,說(shuō)明編寫(xiě)的數(shù)據(jù)格式有問(wèn)題,修改為正確格式即可創(chuàng)建成。隨后可以在postman中進(jìn)行驗(yàn)證:
ajax通過(guò)get方法獲取數(shù)據(jù):
根據(jù)獲取出來(lái)得階段數(shù)據(jù)來(lái)更改相對(duì)應(yīng)得進(jìn)度:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>document</title> <link rel="stylesheet" href="2.css" rel="external nofollow" > <script src="2.js"></script> <script src="jquery.min.js"></script> </head> <body> <div class="box"> <div class="pr1"> <span class="circle">1 <span class="line"> <span class="cont1">科研人員申報(bào) </div> <div class="pr1"> <span class="circle">2 <span class="line"> <span class="cont2">院系申報(bào) </div> <div class="pr1"> <span class="circle">3 <span class="line"> <span class="cont2">專(zhuān)家評(píng)審 </div> <div class="pr1_last"> <span class="circle">4 <span class="cont2">校級(jí)審核 </div> </div> </body> </html>
window.onload = function() { $(function() { var b //使用ajax獲取api中得數(shù)據(jù),看是那個(gè)階段 $.ajax({ type: 'get', url: 'https://mock.mengxuegu.com/mock/624d8ce9f56fd246b02bfcaf/process/getinfo', success: function(res) { console.log(res.data[0].batchstate); b = res.data[0].batchstate; //利用b數(shù)據(jù)去改變狀態(tài)//1未開(kāi)始,2申報(bào)中,3院系審核中,4專(zhuān)家審核中,5校級(jí)審核中,6已結(jié)束 if (b == 1) { $('.cont1').css('color', 'skyblue') $('.circle').eq(0).css('background-color', 'skyblue') } if (b == 2) { $('.line').eq(0).css('border-color', 'green') $('.line').eq(0).css('border-style', 'solid') $('.circle').eq(0).html('√') $('.circle').eq(0).css('background-color', 'green') $('.cont1').css('color', 'green') $('.circle').eq(1).css('background-color', 'skyblue') $('.cont2').eq(0).css('color', 'skyblue') } if (b == 3) { $('.circle').eq(0).html('√') $('.circle').eq(0).css('background-color', 'green') $('.circle').eq(1).html('√') $('.cont2').eq(0).css('color', 'green') $('.circle').eq(1).css('background-color', 'green') $('.cont1').css('color', 'green') $('.line').eq(0).css('border-color', 'green') $('.line').eq(1).css('border-color', 'green') $('.line').eq(0).css('border-style', 'solid') $('.line').eq(1).css('border-style', 'solid') $('.circle').eq(2).css('background-color', 'skyblue') $('.cont2').eq(1).css('color', 'skyblue') } if (b == 4) { $('.circle').eq(0).html('√') $('.circle').eq(0).css('background-color', 'green') $('.circle').eq(1).html('√') $('.cont2').eq(0).css('color', 'green') $('.cont2').eq(1).css('color', 'green') $('.circle').eq(1).css('background-color', 'green') $('.circle').eq(2).css('background-color', 'green') $('.cont1').css('color', 'green') $('.line').eq(0).css('border-color', 'green') $('.line').eq(1).css('border-color', 'green') $('.line').eq(2).css('border-color', 'green') $('.line').eq(0).css('border-style', 'solid') $('.line').eq(1).css('border-style', 'solid') $('.line').eq(2).css('border-style', 'solid') $('.circle').eq(3).css('background-color', 'skyblue') $('.cont2').eq(2).css('color', 'skyblue') } } }) }) }
* { margin: 0px; padding: 0px; } .box { width: 305px; height: 40px; margin: 20px auto; line-height: 40px; } .circle { position: absolute; top: 10px; left: 0px; display: inline-block; width: 20px; height: 20px; border-radius: 50%; -moz-border-radius: 50%; -webkit-border-radius: 50%; background-color: grey; line-height: 20px; text-align: center; color: white } .line { position: absolute; top: 20px; left: 19px; display: inline-block; width: 70px; height: 0px; border-top: grey 1px; margin: 0px; border-top-style: dotted } .pr1 { float: left; width: 90px; height: 40px; position: relative; text-align: center; } .pr1_last { float: left; width: 35px; height: 40px; position: relative; text-align: center; } .cont1 { position: absolute; top: 18px; left: -20px; font-size: 10px; color: grey } .cont2 { position: absolute; top: 18px; left: -10px; font-size: 10px; color: grey }
到此這篇關(guān)于使用ajax實(shí)現(xiàn)進(jìn)度條的繪制的文章就介紹到這了,更多相關(guān)ajax進(jìn)度條內(nèi)容請(qǐng)搜索碩編程以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持碩編程!