tween.js/examples/15_complex_properties.html
Joe Pea df8214619f examples: fix 14_pause_tween which was trying to use the removed
relative values feature (`start('+500')`) and make it use `.delay(500)`
instead, and avoid using negative values for delaye (`.delay(-500)`) in
the 13_relative_start_time example because it may not be intuitive and
plus that feature broke with the previous merge that fixed more
important timing issues (especially with unfocused browser tabs)

BREAKING: If you are using negative values for delay, f.e.
`tween.delay(-500)`, instead manage the time values passed to your
tweens manually. For example:

```js
tweenOffset = 500
const tween = new Tween(...)
tween.start(currentTime)
tween.update(currentTime + tweenOffset) // advance it immediate immediately, as if it already started earlier

// in the update loop
tween.update(newCurrentTime + tweenOffset)
```
2024-01-14 22:55:52 -08:00

73 lines
1.7 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<title>Tween.js / complex properties</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>15 _ complex properties</h2>
<p>Simple example for illustrating animation of nested properties.</p>
</div>
<div
id="target"
style="
position: absolute;
transform: translate(100px, 100px);
width: 100px;
height: 100px;
background: #a0dde9;
padding: 1em;
"
>
hello world!
</div>
<script src="../dist/tween.umd.js"></script>
<script>
var position
var target
var tween, tweenBack
init()
animate()
function init() {
position = {x: 100, y: 100, styles: {opacity: 1.0}}
target = document.getElementById('target')
tween = new TWEEN.Tween(position)
.to({x: 700, y: 200, styles: {opacity: 0}}, 1000)
.delay(1000)
.onUpdate(update)
tweenBack = new TWEEN.Tween(position)
.to({x: 100, y: 100, styles: {opacity: 1.0}}, 1000)
.onUpdate(update)
tween.chain(tweenBack)
tweenBack.chain(tween)
tween.start()
}
//If we register the callback animate, but the TWEEN.update(time) returns false,
//cancel/unregister the handler
function animate(time) {
var id = requestAnimationFrame(animate)
var result = TWEEN.update(time)
if (!result) cancelAnimationFrame(id)
}
function update(values) {
target.style.opacity = values.styles.opacity
target.style.transform = `translate(${values.x}px, ${values.y}px)`
}
</script>
</body>
</html>