• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

영상 속 코드와 배포하신 소스 코드가 다르네요.

23.01.30 09:52 작성 23.01.30 09:52 수정 조회수 484

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>

복붙해서 사용하세요.

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!