tween.js/examples/04_simplest.html
2012-04-10 03:19:28 +02:00

56 lines
1.3 KiB
HTML

<!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/sole/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>
<div id="target" style="position: absolute; left: 50px; top: 300px; font-size: 100px; letter-spacing: -7px; ">
</div>
<script src="../build/Tween.js"></script>
<script src="js/RequestAnimationFrame.js"></script>
<script>
init();
animate();
function init() {
var output = document.createElement( 'div' );
var target = document.getElementById( 'target' );
target.appendChild( output );
var tween = new TWEEN.Tween( { x: 50, y: 0 } )
.to( { x: 400 }, 2000 )
.easing( TWEEN.Easing.Elastic.InOut )
.onUpdate( function () {
output.innerHTML = 'x == ' + Math.round( this.x );
target.style.left = this.x + 'px';
} )
.start();
}
function animate() {
requestAnimationFrame( animate );
TWEEN.update();
}
</script>
</body>
</html>