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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5096 | PHP | 3년 전 | 1499 | ||
| 5095 | JavaScript | 3년 전 | 2127 | ||
| 5094 | JavaScript | 3년 전 | 2046 | ||
| 5093 | 기타 | 3년 전 | 1415 | ||
| 5092 | JavaScript | 3년 전 | 1962 | ||
| 5091 | 기타 |
|
3년 전 | 1321 | |
| 5090 | 기타 |
|
3년 전 | 2257 | |
| 5089 | 웹서버 |
|
3년 전 | 3330 | |
| 5088 | JavaScript | 3년 전 | 2060 | ||
| 5087 | 기타 | 3년 전 | 1661 | ||
| 5086 | 웹서버 |
|
3년 전 | 1703 | |
| 5085 | node.js | 3년 전 | 1646 | ||
| 5084 | JavaScript |
DogFoot개발
|
3년 전 | 1454 | |
| 5083 | 웹서버 |
DogFoot개발
|
3년 전 | 2989 | |
| 5082 | JavaScript |
DogFoot개발
|
3년 전 | 4027 | |
| 5081 | JavaScript |
DogFoot개발
|
3년 전 | 2100 | |
| 5080 | JavaScript |
DogFoot개발
|
3년 전 | 2439 | |
| 5079 | 기타 |
DogFoot개발
|
3년 전 | 2493 | |
| 5078 | OS | 3년 전 | 1650 | ||
| 5077 | 웹서버 |
DogFoot개발
|
3년 전 | 1723 | |
| 5076 | 기타 |
DogFoot개발
|
3년 전 | 1535 | |
| 5075 | 기타 |
DogFoot개발
|
3년 전 | 1677 | |
| 5074 | 기타 | 3년 전 | 2284 | ||
| 5073 | 기타 | 3년 전 | 2554 | ||
| 5072 | 웹서버 |
|
4년 전 | 2234 | |
| 5071 | 웹서버 | 4년 전 | 3236 | ||
| 5070 | PHP | 4년 전 | 3198 | ||
| 5069 | 웹서버 | 4년 전 | 2433 | ||
| 5068 | 기타 |
|
4년 전 | 3014 | |
| 5067 | 기타 |
DogFoot개발
|
4년 전 | 2684 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기