Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2014 19:11
Show Gist options
  • Save anonymous/a0f64c5a15edf0fbd1f5 to your computer and use it in GitHub Desktop.
Save anonymous/a0f64c5a15edf0fbd1f5 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
body {
font-family: Segoe UI;
font-size: 11px;
}
.progress {
background-color: #BDE;
border: 1px solid #CCC;
box-sizing: border-box;
transition: width 0.5s ease;
-webkit-transition: all 0.5s ease;
}
.progress-container {
background-color: #EEE;
height: 20px;
text-align: center;
line-height: 18px;
}
</style>
</head>
<body>
<div class="progress-container"></div>
<script id="jsbin-javascript">
function progress(options) {
var el = document.querySelector(options.selector);
var prog = el.firstChild;
if (!el.firstChild || el.firstChild.className !== options.progressClassName) {
while (el.firstChild) {
el.removeChild(el.firstChild);
}
prog = document.createElement('div');
el.appendChild(prog);
}
prog.style.height = '100%';
prog.style.width = options.percent + '%';
prog.className = options.progressClassName;
if (options.showPercent) {
prog.innerHTML = options.percent + '%';
}
}
var i = 0;
function update() {
progress({
selector: '.progress-container',
percent: i++,
progressClassName: 'progress',
showPercent: true
});
i += 5
if (i <= 100) {
setTimeout(update, 1000)
} else {
i = 0;
setTimeout(update, 1000)
}
}
update()
</script>
<script id="jsbin-source-css" type="text/css">body {
font-family: Segoe UI;
font-size: 11px;
}
.progress {
background-color: #BDE;
border: 1px solid #CCC;
box-sizing: border-box;
transition: width 0.5s ease;
-webkit-transition: all 0.5s ease;
}
.progress-container {
background-color: #EEE;
height: 20px;
text-align: center;
line-height: 18px;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">function progress(options) {
var el = document.querySelector(options.selector);
var prog = el.firstChild;
if (!el.firstChild || el.firstChild.className !== options.progressClassName) {
while (el.firstChild) {
el.removeChild(el.firstChild);
}
prog = document.createElement('div');
el.appendChild(prog);
}
prog.style.height = '100%';
prog.style.width = options.percent + '%';
prog.className = options.progressClassName;
if (options.showPercent) {
prog.innerHTML = options.percent + '%';
}
}
var i = 0;
function update() {
progress({
selector: '.progress-container',
percent: i++,
progressClassName: 'progress',
showPercent: true
});
i += 5
if (i <= 100) {
setTimeout(update, 1000)
} else {
i = 0;
setTimeout(update, 1000)
}
}
update()</script></body>
</html>
body {
font-family: Segoe UI;
font-size: 11px;
}
.progress {
background-color: #BDE;
border: 1px solid #CCC;
box-sizing: border-box;
transition: width 0.5s ease;
-webkit-transition: all 0.5s ease;
}
.progress-container {
background-color: #EEE;
height: 20px;
text-align: center;
line-height: 18px;
}
function progress(options) {
var el = document.querySelector(options.selector);
var prog = el.firstChild;
if (!el.firstChild || el.firstChild.className !== options.progressClassName) {
while (el.firstChild) {
el.removeChild(el.firstChild);
}
prog = document.createElement('div');
el.appendChild(prog);
}
prog.style.height = '100%';
prog.style.width = options.percent + '%';
prog.className = options.progressClassName;
if (options.showPercent) {
prog.innerHTML = options.percent + '%';
}
}
var i = 0;
function update() {
progress({
selector: '.progress-container',
percent: i++,
progressClassName: 'progress',
showPercent: true
});
i += 5
if (i <= 100) {
setTimeout(update, 1000)
} else {
i = 0;
setTimeout(update, 1000)
}
}
update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment