-
Notifications
You must be signed in to change notification settings - Fork 1
/
knightrider.html
55 lines (47 loc) · 1.36 KB
/
knightrider.html
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
45
46
47
48
49
50
51
52
53
54
<style>
body {
background: black;
}
b {
height: 10px;
width: 10px;
display: inline-block;
background: red;
border: 1px solid black;
}
</style>
<b data-bind="style: { opacity: bars[0] }"></b>
<b data-bind="style: { opacity: bars[1] }"></b>
<b data-bind="style: { opacity: bars[2] }"></b>
<b data-bind="style: { opacity: bars[3] }"></b>
<b data-bind="style: { opacity: bars[4] }"></b>
<b data-bind="style: { opacity: bars[5] }"></b>
<script src="http://localhost/~chris/iosbin/knockout-latest.debug.js"></script>
<script>
var viewModel = {
ticks: ko.observable(0),
tick: function() {
this.ticks(this.ticks() + 1);
},
bars: []
};
function createBar(index, count) {
return ko.computed(function() {
var a = viewModel.ticks() % ((count - 1) * 2);
var b = Math.abs(a - count + 1);
var c = Math.abs(index - b);
var d = c / count;
var e = 1 - d;
return (e * e * e).toFixed(3);
});
}
for (var index = 0, count = 6; index < count; index++) {
viewModel.bars[index] = createBar(index, count);
}
</script>
<script>
setInterval(function() {
viewModel.tick();
}, 100);
ko.applyBindings(viewModel);
</script>