使用Ajax實(shí)現(xiàn)進(jìn)度條的繪制
使用:Easy Mock創(chuàng)建api接口

注意:若彈出該invalid or unexpected token錯(cuò)誤提示信息,說明編寫的數(shù)據(jù)格式有問題,修改為正確格式即可創(chuàng)建成。隨后可以在postman中進(jìn)行驗(yàn)證:

ajax通過GET方法獲取數(shù)據(jù):

根據(jù)獲取出來得階段數(shù)據(jù)來更改相對(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>
<span class="line"></span>
<span class="cont1">科研人員申報(bào)</span>
</div>
<div class="pr1">
<span class="circle">2</span>
<span class="line"></span>
<span class="cont2">院系申報(bào)</span>
</div>
<div class="pr1">
<span class="circle">3</span>
<span class="line"></span>
<span class="cont2">專家評(píng)審</span>
</div>
<div class="pr1_last">
<span class="circle">4</span>
<span class="cont2">校級(jí)審核</span>
</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未開始,2申報(bào)中,3院系審核中,4專家審核中,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)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Json數(shù)據(jù)異步綁定到界面的Table并且自動(dòng)刷新原理及代碼
做Winform習(xí)慣了,大家都習(xí)慣設(shè)置datasource這樣的寫法,今天就先從這個(gè)updatepanel加timer實(shí)現(xiàn)頁面自動(dòng)刷新這個(gè)例子來下手吧,感興趣的朋友可以了解下,或許對(duì)你學(xué)習(xí)ajax有所幫助2013-02-02
ajax處理服務(wù)器返回的三種數(shù)據(jù)類型方法
這篇文章主要介紹了ajax如何處理服務(wù)器返回的三種數(shù)據(jù)類型,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10
ajax讀取數(shù)據(jù)庫內(nèi)容實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)下拉選擇菜單示例
本文為大家介紹下使用ajax技術(shù)讀取數(shù)據(jù)庫內(nèi)容并生成二級(jí)聯(lián)動(dòng)下拉選擇菜單,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-07-07
關(guān)于JavaScript跨域問題及實(shí)時(shí)刷新解決方案
在頁面顯示其他網(wǎng)站上面的數(shù)據(jù),需要用Ajax,就涉及到跨域問題,下面有個(gè)示例,大家可以看看2014-06-06
Ajax實(shí)現(xiàn)帶有驗(yàn)證碼的局部刷新登錄界面
很多登錄界面都有驗(yàn)證碼功能局部刷新效果,接下來通過本文給大家分享ajax實(shí)現(xiàn)帶有驗(yàn)證碼的局部刷新登錄界面,感興趣的朋友一起看看吧2016-09-09

