mirror of
https://github.com/tweenjs/tween.js.git
synced 2026-02-01 17:27:10 +00:00
100 lines
2.5 KiB
HTML
100 lines
2.5 KiB
HTML
<!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>
|
|
</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: 300px; top: 0px">
|
|
yoyo with repeat forever
|
|
</div>
|
|
</div>
|
|
|
|
<script src="../src/Tween.js"></script>
|
|
<script src="js/RequestAnimationFrame.js"></script>
|
|
<script>
|
|
|
|
init();
|
|
animate();
|
|
|
|
function init() {
|
|
var target1 = document.getElementById( 'target1' ),
|
|
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() {
|
|
updateBox( target1, this );
|
|
})
|
|
.start(),
|
|
target2 = document.getElementById( 'target2' ),
|
|
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() {
|
|
updateBox( target2, this );
|
|
})
|
|
.start();
|
|
}
|
|
|
|
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;
|
|
}
|
|
</style>
|
|
</body>
|
|
</html>
|