mirror of
https://github.com/tweenjs/tween.js.git
synced 2025-12-08 20:16:12 +00:00
76 lines
1.8 KiB
HTML
76 lines
1.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Tween.js / video and 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>05 _ video and time</h2>
|
|
<p>Playing a video, synchronizing a tween to it. <button id="playButton">Play</button></p>
|
|
</div>
|
|
|
|
<div
|
|
id="target"
|
|
style="
|
|
position: absolute;
|
|
left: 0px;
|
|
top: 300px;
|
|
transform: translateX(50px);
|
|
font-size: 100px;
|
|
letter-spacing: -7px;
|
|
"
|
|
>
|
|
<video id="video" src="video/sintel.webm" width="320" height="138"></video>
|
|
</div>
|
|
|
|
<script src="../dist/tween.umd.js"></script>
|
|
<script src="js/RequestAnimationFrame.js"></script>
|
|
<script type="module">
|
|
var video
|
|
|
|
playButton.addEventListener('click', function () {
|
|
init()
|
|
animate()
|
|
})
|
|
|
|
function init() {
|
|
var output = document.createElement('div')
|
|
|
|
var target = document.getElementById('target')
|
|
target.appendChild(output)
|
|
|
|
video = document.getElementById('video')
|
|
video.addEventListener(
|
|
'play',
|
|
function () {
|
|
new TWEEN.Tween({x: 50, y: 0})
|
|
.to({x: 400}, this.duration)
|
|
.easing(TWEEN.Easing.Linear.None)
|
|
.onUpdate(function (object) {
|
|
var roundX = Math.round(object.x)
|
|
var transform = 'translateX(' + roundX + 'px)'
|
|
output.innerHTML = 'x == ' + roundX
|
|
target.style.transform = transform
|
|
})
|
|
.start(video.currentTime)
|
|
},
|
|
false,
|
|
)
|
|
|
|
video.play()
|
|
}
|
|
|
|
function animate() {
|
|
if (video.readyState === video.HAVE_ENOUGH_DATA) {
|
|
TWEEN.update(video.currentTime)
|
|
}
|
|
|
|
requestAnimationFrame(animate)
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|