forked from tweenjs/tween.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_yoyo.html
169 lines (157 loc) · 4.19 KB
/
10_yoyo.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tween.js / yoyo</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>10 _ yoyo</h2>
<p>Demonstrating the yoyo() feature.</p>
<button onclick="restart()">restart</button>
<button onclick="stop()">stop</button>
<button onclick="start()">start</button>
<button onclick="pause()">pause</button>
<button onclick="resume()">resume</button>
</div>
<div style="position: absolute; top: 100px; left: 400px;">
<div id="target1" data-rotation="0" data-y="0" class="box" style="left: 0px; top: 0px;">
yoyo with repeat once
</div>
<div id="target2" data-rotation="0" data-y="0" class="box" style="left: 200px; top: 0px;">
yoyo with repeat forever
</div>
<div id="target3" data-rotation="0" data-y="0" class="box" style="left: 400px; top: 0px;">
yoyo with repeat once, relative values
</div>
<div id="target4" data-rotation="0" data-y="0" class="box" style="left: 600px; top: 0px;">
yoyo with repeat forever, relative values
</div>
</div>
<script src="../dist/tween.umd.js"></script>
<script src="js/RequestAnimationFrame.js"></script>
<script>
init()
animate()
var restart, stop, start, pause, resume
function init() {
var target1 = document.getElementById('target1')
var tween1 = new TWEEN.Tween(target1.dataset)
.to({rotation: 360, y: 300}, 750)
.repeat(1)
.delay(1000)
.yoyo(true)
.easing(TWEEN.Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target1, object)
})
.start()
var target2 = document.getElementById('target2')
var tween2 = new TWEEN.Tween(target2.dataset)
.to({rotation: 360, y: 300}, 750)
.repeat(Infinity)
.delay(1000)
.yoyo(true)
.easing(TWEEN.Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target2, object)
})
.start()
var target3 = document.getElementById('target3')
var tween3 = new TWEEN.Tween(target3.dataset)
.to({rotation: '+360', y: '+300'}, 750)
.repeat(1)
.delay(1000)
.yoyo(true)
.easing(TWEEN.Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target3, object)
})
.start()
var target4 = document.getElementById('target4')
var tween4 = new TWEEN.Tween(target4.dataset)
.to({rotation: '+360', y: '+300'}, 750)
.repeat(Infinity)
.delay(1000)
.yoyo(true)
.easing(TWEEN.Easing.Cubic.InOut)
.onUpdate(function (object) {
updateBox(target4, object)
})
.start()
restart = function () {
tween1.stop().start()
tween2.stop().start()
tween3.stop().start()
tween4.stop().start()
}
stop = function () {
tween1.stop()
tween2.stop()
tween3.stop()
tween4.stop()
}
start = function () {
tween1.start()
tween2.start()
tween3.start()
tween4.start()
}
pause = function () {
tween1.pause()
tween2.pause()
tween3.pause()
tween4.pause()
}
resume = function () {
tween1.resume()
tween2.resume()
tween3.resume()
tween4.resume()
}
}
function animate(time) {
requestAnimationFrame(animate)
TWEEN.update(time)
}
function updateBox(box, params) {
var s = box.style,
transform = 'translateY(' + Math.round(params.y) + 'px) 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;
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;
}
#target3 {
background: orange;
}
#target4 {
background: skyblue;
}
</style>
</body>
</html>