forked from LeaVerou/HTML5-Progress-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-interaction.js
44 lines (36 loc) · 1.23 KB
/
user-interaction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Interaction demos for the <progress> polyfill
* Demonstrates setting the progress value through Javascript
* @author Espen Hovlandsdal http://rexxars.com
*/
(function(d) {
var bind = function(el, event, fn) {
if (el.addEventListener) {
el.addEventListener(event, fn, false);
} else {
el.attachEvent('on' + event, fn)
}
};
var dyn = d.getElementById('dynamicProgress'), timer, progress = 0;
var el = dyn.getElementsByTagName('progress')[0];
var perc = dyn.getElementsByClassName('percentage')[0];
var progressTo = function(to) {
clearInterval(timer);
var inc = to < el.value ? -1 : 1;
timer = setInterval(function() {
progress += inc;
el.value = progress;
perc.innerHTML = progress;
if (progress == to) {
return clearInterval(timer);
}
}, 25);
};
bind(d.getElementById('animateFully'), 'click', function() {
progressTo(100);
});
bind(d.getElementById('animateToUserInput'), 'click', function() {
var to = parseInt(prompt('How many percent?', 50), 10);
progressTo(Math.max(0, Math.min(100, to)));
});
})(document);