-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
11_stop_all_chained_tweens.html
104 lines (92 loc) · 2.4 KB
/
11_stop_all_chained_tweens.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
98
99
100
101
102
103
104
<!doctype html>
<html lang="en">
<head>
<title>Tween.js / stop chained</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>11 _ stop all chained tweens.</h2>
<p>Tween#stopChainedTweens</p>
</div>
<div style="position: absolute; top: 250px; left: 50px">
<button id="start">Start</button>
<button id="stop">Stop</button>
<div id="target1" data-rotation="0" data-y="0" class="box" style="left: 0px; top: 50px">Box One</div>
<div id="target2" data-rotation="0" data-y="0" class="box" style="left: 0px; top: 200px">Box Two</div>
</div>
<script type="module">
import * as TWEEN from '../dist/tween.esm.js'
const group = new TWEEN.Group()
function animate(time) {
group.update(time)
requestAnimationFrame(animate)
}
animate()
const a = document.getElementById('target1')
const b = document.getElementById('target2')
const start = document.getElementById('start')
const stop = document.getElementById('stop')
let t0, t1
const p0 = {x: 0},
p1 = {x: 0}
start.onclick = function () {
if (!t0 && !t1) {
t0 = new TWEEN.Tween(p0, group)
.to({x: 700}, 2000)
.delay(100)
.easing(TWEEN.Easing.Elastic.InOut)
.onUpdate(function () {
a.style.left = p0.x + 'px'
})
.onComplete(function () {
p0.x = 0
a.style.left = p0.x + 'px'
})
t1 = new TWEEN.Tween(p1, group)
.to({x: 1000}, 3000)
.delay(100)
.easing(TWEEN.Easing.Elastic.InOut)
.onUpdate(function () {
b.style.left = p1.x + 'px'
})
.onComplete(function () {
p1.x = 0
b.style.left = p1.x + 'px'
})
t0.chain(t1)
t1.chain(t0)
}
t0.start()
}
stop.onclick = function () {
t0.stop()
}
</script>
<style type="text/css">
.box {
width: 100px;
height: 100px;
display: flex;
flex-flow: row;
align-items: center;
text-align: center;
-webkit-border-radius: 70px;
-moz-border-radius: 70px;
border-radius: 70px;
position: absolute;
border: 1px solid black;
font-size: 10px;
padding: 20px;
}
#target1 {
background: #fcc;
}
#target2 {
background: #cfc;
}
</style>
</body>
</html>