如果我在我的HTML頁面中添加一個進度元素,但是如果我添加了另一個進度元素,則首先運行得非常好,但其次並非如預期的那樣,我創建了一個簡單的基本進度條。爲什麼進度條無法正常工作?
這裏是我的Codepen
HTML:
<div class="ani-progressbar">
<div class="fill-progress" kac-puan="8">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<div class="ani-progressbar">
<div class="fill-progress" kac-puan="10">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
CSS:
.ani-progressbar{
width:100%;
height:5px;
margin-bottom:10px;
}
.fill-progress span{
display:block;
width:5px;
height:5px;
border:1px solid #9ad204;
float:left;
margin-left:1px;
}
jQuery的:
$(document).ready(function(){
var getVal = $(".ani-progressbar .fill-progress").attr("kac-puan");
$(".ani-progressbar .fill-progress span").slice(0,getVal).each(function(index,element){
$(this).css("background","#9ad204");
});
});