I'm building some type of one-bar jQuery chart, everything goes well except for filling animation, with my script all the sections animate in the same time. I want to make each section to animate, complete, wait 0.1 sec then pass the the next.
$('#chart .chart-item').each(function() {
$(this).animate({
width: $(this).data('w') + '%'
}, 1000);
});
.chart {
width: 100%;
margin-top: 40px;
background: #eee;
}
.chart-item {
display: inline-block;
width: 0;
height: 40px;
border-left: 1px solid #fff;
}
.chart-item:first-child {
border-left: none;
}
.chart-item:first-child {
background-color: #0D47A1;
}
.chart-item:nth-child(2) {
background-color: #1565C0;
}
.chart-item:nth-child(3) {
background-color: #1976D2;
}
.chart-item:nth-child(4) {
background-color: #1E88E5;
}
.chart-item:nth-child(5) {
background-color: #2196F3;
}
.chart-item:nth-child(6) {
background-color: #42A5F5;
}
.chart-item:nth-child(7) {
background-color: #64B5F6;
}
.chart-item:nth-child(8) {
background-color: #90CAF9;
}
.chart-item:nth-child(9) {
background-color: #BBDEFB;
}
.chart-item:nth-child(10) {
background-color: #E3F2FD;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="chart" class="chart">
<span class="chart-item" data-w="40.80"></span>
<span class="chart-item" data-w="28.56"></span>
<span class="chart-item" data-w="16.93"></span>
<span class="chart-item" data-w="13.54"></span>
</div>
NB: No problem for the wrap of the last section as in my app it works perfect.
Just add a
delay
before eachanimation
as below:DEMO HERE