video를 연속으로 재생
video 객체에 onended 이벤트가 있네요
다음과 같은 코드로 연속재생을 해봤습니다.
[code]
<style>
#video-box {min-width:1200px; position:relative;}
#video-box .main-banner {display:none; width:100%; height:750px; overflow:hidden;position:relative; background-color:#000;}
#video-box .main-banner.open{display:block;}
#video-box .main-banner video {position:absolute;width:100%;top:50%; left:50%;transform:translate(-50%,-50%);border:0;}
#video-box .dot-box {position:absolute; width:100%; bottom:0; text-align:center;}
#video-box .dot-box a{display:inline-block; margin:0.5em; width:20px;height:20px; border-radius:50%; background-color:#06F;text-indent:-9999px;}
#video-box .dot-box a.open{background-color:yellowgreen;}
@media screen and (max-width:1400px) { #video-box .main-banner {height:550px;} }
</style>
<div id="video-box">
<div class="main-banner open">
<video autoplay muted>
<source src="https://www.bodyfriend.co.kr/video/1.mp4" type="video/mp4">
</video>
</div>
<div class="main-banner">
<video muted>
<source src="https://www.bodyfriend.co.kr/video/main02.mp4" type="video/mp4">
</video>
</div>
<div class="main-banner">
<video muted>
<source src="https://www.bodyfriend.co.kr/video/main03.mp4" type="video/mp4">
</video>
</div>
<div class="dot-box"></div>
</div>
<script>
$(function() {
var len = $('.main-banner').length
$('.main-banner').each(function(index, element) {
$(this).addClass('v' + index);
var video = $(this).find('video')[0];
video.onended = function(e) {
$('.main-banner').removeClass('open');
$('.main-banner.v'+((index+1) % len)).addClass('open');
$('.main-banner.v'+((index+1) % len)).find('video')[0].play();
$('#video-box a.dot').removeClass('open');
$('#video-box a.dot.v'+((index+1) % len)).addClass('open');
};
$('#video-box .dot-box').append('<a href="#" class="dot v'+index+'" data-idx="'+index+'">'+(index+1)+'번째 비디오</a>');
});
$('#video-box a.dot').click(function(e) {
var idx = $(this).data('idx');
$('.main-banner.open').find('video')[0].pause();
$('.main-banner').removeClass('open');
$('.main-banner.v'+(idx % len)).addClass('open');
$('.main-banner.v'+(idx % len)).find('video')[0].play();
$('#video-box a.dot').removeClass('open');
$('#video-box a.dot.v'+(idx % len)).addClass('open');
});
$('#video-box a.dot.v0').addClass('open');
});
</script>
[/code]
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5126 | PHP |
|
3년 전 | 1797 | |
| 5125 | PHP | 3년 전 | 1599 | ||
| 5124 | PHP | 3년 전 | 2117 | ||
| 5123 | OS | 3년 전 | 1397 | ||
| 5122 | OS | 3년 전 | 1313 | ||
| 5121 | OS | 3년 전 | 1419 | ||
| 5120 | OS | 3년 전 | 1296 | ||
| 5119 | PHP |
|
3년 전 | 1143 | |
| 5118 | PHP | 3년 전 | 1356 | ||
| 5117 | Mobile |
|
3년 전 | 1397 | |
| 5116 | PHP | 3년 전 | 2292 | ||
| 5115 | MySQL |
welcome
|
3년 전 | 2904 | |
| 5114 | OS | 3년 전 | 2002 | ||
| 5113 | JavaScript | 3년 전 | 1539 | ||
| 5112 | PHP | 3년 전 | 1559 | ||
| 5111 | 기타 |
|
3년 전 | 1299 | |
| 5110 | PHP | 3년 전 | 4545 | ||
| 5109 | PHP | 3년 전 | 1579 | ||
| 5108 | 기타 |
|
3년 전 | 12175 | |
| 5107 | 기타 |
|
3년 전 | 2408 | |
| 5106 | 기타 |
|
3년 전 | 6323 | |
| 5105 | 기타 |
|
3년 전 | 3695 | |
| 5104 | 기타 |
|
3년 전 | 1501 | |
| 5103 | JavaScript | 3년 전 | 1692 | ||
| 5102 | 기타 |
|
3년 전 | 1270 | |
| 5101 | 기타 |
|
3년 전 | 1466 | |
| 5100 | 기타 |
|
3년 전 | 1306 | |
| 5099 | 웹서버 | 3년 전 | 2171 | ||
| 5098 | PHP | 3년 전 | 1326 | ||
| 5097 | PHP |
|
3년 전 | 1986 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기