작성
·
584
·
수정됨
0
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
height: 500vh;
}
.sample-video {
position: fixed;
top: 0;
left: 0;
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<!-- <video class="sample-video" src="../video/sample-low.mp4" muted></video> -->
<video class="sample-video" src="../video/sample-high.mp4" muted></video>
</div>
<script>
const videoElem = document.querySelector('.sample-video');
let videoDuration;
videoElem.addEventListener('loadeddata', function() {
console.log('비디오 로드 완료');
videoDuration = videoElem.duration;
init();
})
let progress;
let currentFrame;
function init() {
window.addEventListener('scroll', function () {
progress = pageYOffset / (document.body.offsetHeight - window.innerHeight);
console.log(progress);
if (progress < 0) progress = 0;
if (progress > 1) progress = 1;
requestAnimationFrame(function() {
videoElem.currentTime = videoElem.duration * progress;
})
});
}
</script>
</body>
</html>
복붙해서 사용하세요.
답변