Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<div id="wrapper">
<div id="text1"></div>
<div id="bar"><div id="text2"></div></div>
</div>
</body>
</html>
 
#wrapper {
position: relative;
width: 300px;
height:40px;
background-color: #ccc;
}
#bar {
position: relative;
top:0px;
left:0px;
width: 0px;
height:40px;
background-color: green;
overflow: hidden;
}
#text1 {
position: absolute;
top: 15px;
left: 120px;
color: green;
}
#text2 {
position: absolute;
top: 15px;
left: 120px;
color: red;
}
 
window.onload = function () {
var bar = document.getElementById('bar'),
text1 = document.getElementById('text1'),
text2 = document.getElementById('text2');
width = 0;
setInterval(function () {
width += 10;
if (width === 300) {
width = 0;
}
text1.innerHTML = text2.innerHTML = (width/3).toFixed(2)+'%';
bar.style.width = width + 'px';
}, 500);
};
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers