Snippet:
<div id="container">
<div id="bar">
</div>
</div>
CSS Style:
#container {
width: 20px;
height: 150px;
position: relative;
}
#bar {
width: 100%;
height: 100%;
background-color: red;
position: absolute;
bottom: 0px;
}
Javascript Logic:
function Bar(element) {
this.barEl = element;
this.progress = 100;
}
Bar.prototype.setProgress = function (p) {
if(p >= 0) {
this.progress = p;
this.barEl.style.height = this.progress + "%";
}
}
var barObj = new Bar(document.getElementById('bar'));
setInterval(function () {
barObj.setProgress(barObj.progress - 10);
}, 1000);
The code snippet can be viewed on jsfiddle here. The code is not functioning correctly when copied and pasted, which may be due to an onLoad issue. Attempting to use $(document).ready(function() was unsuccessful in solving the problem.