mirror of
https://github.com/tweenjs/tween.js.git
synced 2025-12-08 20:16:12 +00:00
91 lines
2.2 KiB
HTML
91 lines
2.2 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Tween.js / repeat</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>08 _ repeat</h2>
|
|
<p>Demonstrating the repeat() feature.</p>
|
|
</div>
|
|
<div style="position: absolute; top: 100px; left: 400px">
|
|
<div id="target1" data-rotation="0" class="box">repeat once</div>
|
|
<div id="target2" data-rotation="0" class="box">repeat five times</div>
|
|
<div id="target3" data-rotation="0" class="box">repeat forever</div>
|
|
</div>
|
|
|
|
<script src="../dist/tween.umd.js"></script>
|
|
<script>
|
|
init()
|
|
animate()
|
|
|
|
function init() {
|
|
var target1 = document.getElementById('target1'),
|
|
tween1 = new TWEEN.Tween(target1.dataset)
|
|
.to({rotation: 360}, 2000)
|
|
.repeat(1)
|
|
.delay(1000)
|
|
.onUpdate(function (object) {
|
|
updateBox(target1, object)
|
|
})
|
|
.start(),
|
|
target2 = document.getElementById('target2'),
|
|
tween2 = new TWEEN.Tween(target2.dataset)
|
|
.to({rotation: 360}, 2000)
|
|
.repeat(5)
|
|
.delay(1000)
|
|
.onUpdate(function (object) {
|
|
updateBox(target2, object)
|
|
})
|
|
.start(),
|
|
target3 = document.getElementById('target3'),
|
|
tween3 = new TWEEN.Tween(target3.dataset)
|
|
.to({rotation: 360}, 2000)
|
|
.repeat(Infinity)
|
|
.delay(1000)
|
|
.onUpdate(function (object) {
|
|
updateBox(target3, object)
|
|
})
|
|
.start()
|
|
}
|
|
|
|
function animate(time) {
|
|
requestAnimationFrame(animate)
|
|
|
|
TWEEN.update(time)
|
|
}
|
|
|
|
function updateBox(box, params) {
|
|
var s = box.style,
|
|
transform = '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;
|
|
margin: 10px;
|
|
padding: 10px;
|
|
display: inline-block;
|
|
float: left;
|
|
}
|
|
#target1 {
|
|
background: #fcc;
|
|
}
|
|
#target2 {
|
|
background: #cfc;
|
|
}
|
|
#target3 {
|
|
background: #ccf;
|
|
}
|
|
</style>
|
|
</body>
|
|
</html>
|