To achieve this effect, simply utilize Pseudo elements and data-* attributes on the .pb1 class as shown below:
Html:
<div class="volume-container">
<div class="pb1">
<div id="progress-bar"></div>
</div>
</div>
Ensure that .pb1 has a position of relative and add content:attr(data-percentage)" Usage"; to it.
Css:
.volume-container {
width: 100%;
margin: 0 auto;
}
.pb1 {
margin-left:100px;
width: 17.5%;
border: 1px solid;
background: #dddddd;
position:relative;
}
.pb1:before,.pb1:after{
position:absolute;
top:0;
}
.pb1:before{
left:-100px;
content:"analysis volume"
}
.pb1:after{
content:attr(data-percentage)" Usage";
right:-100px;
}
#progress-bar, #progress-bar2 {
width: 0;
height: 13px;
line-height: 20px;
background: #79a151;
font-family: calibri;
color: white;
text-align: center;
overflow: hidden;
}
Next, set $('.pb1').attr('data-percentage',width); to .pb1
Js:
var progressBar = $('#progress-bar'),
width = 0;
progressBar.width(width);
var interval = setInterval(function() {
width += 1;
$('.pb1').attr('data-percentage',width);
progressBar.css('width', width + '%');
document.getElementById("progress-bar").innerHTML = width;
if (width >= 100) {
clearInterval(interval);
}
}, 100);