forked from tweenjs/tween.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
09_relative_values.html
67 lines (63 loc) · 1.7 KB
/
09_relative_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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tween.js / relative 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" />
<style type="text/css">
.box {
width: 100px;
height: 100px;
margin: 10px;
padding: 10px;
display: inline-block;
float: left;
}
#target1 {
background: #fcc;
}
</style>
<script src="../dist/tween.umd.js"></script>
<script src="js/RequestAnimationFrame.js"></script>
<script>
window.onload = function () {
init()
animate()
}
function init() {
var target1 = document.getElementById('target1'),
tween1 = new TWEEN.Tween(target1.dataset)
.to({top: '+20', left: '-20'}, 500)
.repeat(5)
.delay(500)
.easing(TWEEN.Easing.Exponential.In)
.onUpdate(function (object) {
object.top = Math.round(object.top)
object.left = Math.round(object.left)
updateBox(target1, object)
})
.start()
updateBox(target1, target1.dataset)
}
function animate(time) {
requestAnimationFrame(animate)
TWEEN.update(time)
}
function updateBox(box, params) {
var s = box.style
var transform = 'translate(' + params.left + 'px, ' + params.top + 'px)'
s.transform = transform
}
</script>
</head>
<body>
<div id="info">
<h1><a href="http://github.com/tweenjs/tween.js">tween.js</a></h1>
<h2>09 _ relative values</h2>
<p>Tweening to relative values, with repeat.</p>
</div>
<div style="position: absolute; left: 400px;">
<div id="target1" style="position: absolute;" data-top="150" data-left="150" class="box"></div>
</div>
</body>
</html>