추가 파일을로드하지 않고 YouTube 플레이어 API를 구현 한 것입니다. 이 작업을 수행하려면 의 src
속성에 모두 ?enablejsapi=1
이라는 접미사를 사용해야합니다.
<div id="pic3">
<iframe width="640" height="390"
src="http://www.youtube.com/embed/Xub4grFLbQM?enablejsapi=1"
frameborder="0" allowfullscreen></iframe>
</div>
<div id="tS2" class="jThumbnailScroller">
.. Removed your code for readability....
<a href="#vid3" id="link3"><img src="images/thumbs/player2.jpg" height="85"/></a>
....
자바 스크립트 + jQuery 코드를 :
예 (I, 당신은 안전하게 바꿈을 생략 할 수 가독성을 위해 몇 줄에 걸쳐 코드를 파산)
$(function() {
/* elt: Optionally, a HTMLIFrameElement. This frame's video will be played,
* if possible. Other videos will be paused*/
function playVideoAndPauseOthers(frame) {
$('iframe[src*="http://www.youtube.com/embed/"]').each(function(i) {
var func = this === frame ? 'playVideo' : 'pauseVideo';
this.contentWindow.postMessage('{"event":"command","func":"' + func + '","args":""}', '*');
});
}
$('#tS2 a[href^="#vid"]').click(function() {
var frameId = /#vid(\d+)/.exec($(this).attr('href'));
if (frameId !== null) {
frameId = frameId[1]; // Get frameId
playVideoAndPauseOthers($('#pic' + frameId + ' iframe')[0]);
}
});
});
영상 원 [의
가능한 중복 ' div가 숨겨져있을 때 중지] (http://stackoverflow.com/questions/8667882/video-wont-stop-when-div-is-hidden) –
참조 : http://stackoverflow.com/questions/1094397/how -can-i-stop-a-video-with-javascript-in-youtube – xbonez
@xbonez 귀하의 질문에 대한 ** 프레임 ** YouTube 비디오 아니에요 . –