tween.js/examples/14_pause_tween.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

91 lines
1.7 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<title>Tween.js / pause tween</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>14 _ pause tween</h2>
<br />
<p>
<button type="button" onclick="pause()">Pause</button>
, then
<button type="button" onclick="resume()">Resume</button>.
</p>
</div>
<div
id="progress_bar_wrapper"
style="
position: absolute;
top: 300px;
left: 100px;
width: 500px;
height: 100px;
border: 0.5em solid black;
overflow: hidden;
"
>
<div
id="progress_bar_fill"
style="
position: absolute;
top: 0px;
left: 0px;
width: 0%;
height: 100%;
background: #a0dde9;
line-height: 6em;
text-align: center;
"
>
0%
</div>
</div>
<script src="../dist/tween.umd.js"></script>
<script>
var progress
var fill
var tween1
init()
animate()
function init() {
progress = {width: 0}
fill = document.getElementById('progress_bar_fill')
tween1 = new TWEEN.Tween(progress)
.to({width: 100}, 2000)
.onUpdate(update1)
.yoyo(true)
.repeat(Infinity)
.delay(500)
.start()
}
function animate(time) {
requestAnimationFrame(animate)
TWEEN.update(time)
}
function update1() {
fill.style.width = progress.width + '%'
fill.innerHTML = Math.floor(progress.width) + '%'
}
function pause() {
tween1.pause()
}
function resume() {
tween1.resume()
}
</script>
</body>
</html>