-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy path16_animate_an_array_of_values.html
70 lines (65 loc) · 1.71 KB
/
16_animate_an_array_of_values.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
<!doctype html>
<html lang="en">
<head>
<title>Tween.js / animate an array of values</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>16 _ animate an array of values</h2>
<p>Animate multiple objects with a single tween using an array of values.</p>
</div>
<div class="container">
<div id="target0" class="box">one</div>
<div id="target1" class="box">two</div>
<div id="target2" class="box">three</div>
</div>
<script type="module">
import * as TWEEN from '../dist/tween.esm.js'
const axes = ['Y', 'Z', 'X']
const tween1 = new TWEEN.Tween([0, 0, 0])
.to([360, 540, '+180'], 2000)
.repeat(1)
.delay(1000)
.easing(TWEEN.Easing.Cubic.InOut)
.onUpdate(function (rotations) {
for (let i = 0; i < rotations.length; i++)
document.getElementById('target' + i).style.transform =
'rotate' + axes[i] + '(' + Math.floor(rotations[i]) + 'deg)'
})
.start()
animate()
function animate(time) {
// Keep requesting frames only if we still need to update.
if (tween1.update(time)) requestAnimationFrame(animate)
}
</script>
<style type="text/css">
.container {
position: absolute;
top: 180px;
left: 400px;
perspective: 400px;
}
.box {
width: 100px;
height: 100px;
margin: 10px;
padding: 10px;
/* display: inline-block; */
float: left;
}
#target0 {
background: #fcc;
}
#target1 {
background: #cfc;
}
#target2 {
background: #ccf;
}
</style>
</body>
</html>