-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
08_repeat.html
97 lines (88 loc) · 2.36 KB
/
08_repeat.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!doctype html>
<html lang="en">
<head>
<title>Tween.js / repeat</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="info">
<h1><a href="http://github.com/tweenjs/tween.js">tween.js</a></h1>
<h2>08 _ repeat</h2>
<p>Demonstrating the repeat() feature.</p>
</div>
<div style="position: absolute; top: 100px; left: 400px">
<div id="target1" data-rotation="0" class="box">no repeat</div>
<div id="target2" data-rotation="0" class="box">repeat twice</div>
<div id="target3" data-rotation="0" class="box">repeat forever</div>
</div>
<script type="module">
import {Tween, Group, Easing} from '../dist/tween.esm.js'
const group = new Group()
init()
animate()
function init() {
const target1 = document.getElementById('target1'),
tween1 = new Tween(target1.dataset)
.to({rotation: 360}, 1000)
.easing(Easing.Exponential.InOut)
.delay(100)
.onUpdate(function (object) {
updateBox(target1, object)
})
.start(),
target2 = document.getElementById('target2'),
tween2 = new Tween(target2.dataset)
.to({rotation: 360}, 1000)
.easing(Easing.Exponential.InOut)
.repeat(2)
.delay(100)
.onUpdate(function (object) {
updateBox(target2, object)
})
.start(),
target3 = document.getElementById('target3'),
tween3 = new Tween(target3.dataset)
.to({rotation: 360}, 1000)
.easing(Easing.Exponential.InOut)
.repeat(Infinity)
.delay(100)
.onUpdate(function (object) {
updateBox(target3, object)
})
.start()
group.add(tween1, tween2, tween3)
}
function animate(time) {
requestAnimationFrame(animate)
group.update(time)
}
function updateBox(box, params) {
const s = box.style,
transform = 'rotate(' + Math.floor(params.rotation) + 'deg)'
s.webkitTransform = transform
s.mozTransform = transform
s.transform = transform
}
</script>
<style type="text/css">
.box {
width: 100px;
height: 100px;
margin: 10px;
padding: 10px;
display: inline-block;
float: left;
}
#target1 {
background: #fcc;
}
#target2 {
background: #cfc;
}
#target3 {
background: #ccf;
}
</style>
</body>
</html>