forked from tweenjs/tween.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
04_simplest.html
52 lines (40 loc) · 1.31 KB
/
04_simplest.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tween.js / simplest possible example!</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>04 _ simplest possible example</h2>
<p>Creating a tween and doing little else apart from that :)</p>
</div>
<script src="../src/Tween.js"></script>
<script src="js/RequestAnimationFrame.js"></script>
<script>
init();
animate();
function init() {
var output = document.createElement( 'div' );
output.style.cssText = 'position: absolute; left: 50px; top: 300px; font-size: 100px';
document.body.appendChild( output );
var tween = new TWEEN.Tween( { x: 50, y: 0 } )
.to( { x: 400 }, 2000 )
.easing( TWEEN.Easing.Elastic.InOut )
.onUpdate( function (object) {
output.innerHTML = 'x == ' + Math.round( object.x );
var transform = 'translateX(' + object.x + 'px)';
output.style.webkitTransform = transform;
output.style.transform = transform;
} )
.start();
}
function animate( time ) {
requestAnimationFrame( animate );
TWEEN.update( time );
}
</script>
</body>
</html>