-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy path13_relative_start_time.html
83 lines (72 loc) · 1.91 KB
/
13_relative_start_time.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
<!doctype html>
<html lang="en">
<head>
<title>Tween.js / relative start time</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>13 _ relative start time</h2>
<br />
<p>One starts late, Two starts early.</p>
</div>
<div
id="target1"
style="
position: absolute;
transform: translate(100px, 100px);
width: 100px;
height: 100px;
background: #a0dde9;
padding: 1em;
"
>
One
</div>
<div
id="target2"
style="
position: absolute;
transform: translate(100px, 300px);
width: 100px;
height: 100px;
background: #a0dde9;
padding: 1em;
"
>
Two
</div>
<script type="module">
import * as TWEEN from '../dist/tween.esm.js'
const position1 = {x: 100, y: 100, rotation: 0}
const position2 = {x: 100, y: 300, rotation: 0}
const target1 = document.getElementById('target1')
const target2 = document.getElementById('target2')
const tween1 = new TWEEN.Tween(position1)
.to({x: 700, y: 200, rotation: 359}, 2000)
.easing(TWEEN.Easing.Elastic.InOut)
.onUpdate(update1)
const tween2 = new TWEEN.Tween(position2).to({x: 500, y: 300, rotation: -90}, 2000).onUpdate(update2)
tween1.delay(2000).start()
tween2.delay(100).start()
animate()
function animate(time) {
requestAnimationFrame(animate)
tween1.update(time)
tween2.update(time)
}
function update1() {
target1.style.transform = `translate(${position1.x}px, ${position1.y}px) rotate(${Math.floor(
position1.rotation,
)}deg)`
}
function update2() {
target2.style.transform = `translate(${position2.x}px, ${position2.y}px) rotate(${Math.floor(
position2.rotation,
)}deg)`
}
</script>
</body>
</html>