mirror of
https://github.com/tweenjs/tween.js.git
synced 2025-12-08 20:16:12 +00:00
90 lines
2.0 KiB
HTML
90 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Tween.js / relative start time</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>13 _ relative start time</h2>
|
|
<br />
|
|
<p>One starts late, Two starts early.</p>
|
|
</div>
|
|
<div
|
|
id="target1"
|
|
style="
|
|
position: absolute;
|
|
transform: translate(100px, 100px);
|
|
width: 100px;
|
|
height: 100px;
|
|
background: #a0dde9;
|
|
padding: 1em;
|
|
"
|
|
>
|
|
One
|
|
</div>
|
|
|
|
<div
|
|
id="target2"
|
|
style="
|
|
position: absolute;
|
|
transform: translate(100px, 300px);
|
|
width: 100px;
|
|
height: 100px;
|
|
background: #a0dde9;
|
|
padding: 1em;
|
|
"
|
|
>
|
|
Two
|
|
</div>
|
|
|
|
<script src="../dist/tween.umd.js"></script>
|
|
<script src="js/RequestAnimationFrame.js"></script>
|
|
<script>
|
|
var position
|
|
var target
|
|
var tween1, tween2
|
|
|
|
init()
|
|
animate()
|
|
|
|
function init() {
|
|
position1 = {x: 100, y: 100, rotation: 0}
|
|
position2 = {x: 100, y: 300, rotation: 0}
|
|
target1 = document.getElementById('target1')
|
|
target2 = document.getElementById('target2')
|
|
|
|
tween1 = new TWEEN.Tween(position1)
|
|
.to({x: 700, y: 200, rotation: 359}, 2000)
|
|
.easing(TWEEN.Easing.Elastic.InOut)
|
|
.onUpdate(update1)
|
|
|
|
tween2 = new TWEEN.Tween(position2).to({x: 500, y: 300, rotation: -90}, 2000).onUpdate(update2)
|
|
|
|
tween1.delay(4000).start()
|
|
tween2.delay(-500).start()
|
|
}
|
|
|
|
function animate(time) {
|
|
requestAnimationFrame(animate)
|
|
|
|
TWEEN.update(time)
|
|
}
|
|
|
|
function update1() {
|
|
target1.style.transform = `translate(${position1.x}px, ${position1.y}px) rotate(${Math.floor(
|
|
position1.rotation,
|
|
)}deg)`
|
|
}
|
|
|
|
function update2() {
|
|
target2.style.transform = `translate(${position2.x}px, ${position2.y}px) rotate(${Math.floor(
|
|
position2.rotation,
|
|
)}deg)`
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|