javascript - pause/play multiple embedded youtube players -
i have 2 thumbnail links, , when clicked on open videos in lightbox style. goal them play when open , pause when closed (they close when background area clicked on).
my html code here:
<body> <div id="page"> <br /><br /><br /><br /><br /> <a id="1" class="thumbnail"rel="nofollow"><img class="img1" src="resources/thumb1.jpg"/></a> <a id="2"class="thumbnail"rel="nofollow"><img class="img1"src="resources/thumb2.jpg" /></a> <div class="backdrop"></div> <div class="video"id="vid1" > <iframe allowscriptaccess="always" class="youtube-player" type="text/html" width="560" height="315" src="http://www.youtube.com/embed/7xhxpebwtus?enablejsapi=1" allowfullscreen="" frameborder="0" id="iframe1"> </iframe> </div> <div class="video"id="vid2"> <iframe allowscriptaccess="always" class="youtube-player" type="text/html" width="560" height="315" src="http://www.youtube.com/embed/pnasz1roxj4?enablejsapi=1" allowfullscreen="" frameborder="0" id="iframe2"> </iframe> </div> <br /><br /><br /><br /> <h1>more come</h1> </div>
and javascript:
$(document).ready(function(){ $('.thumbnail').click(function(){ var $id = $(this).attr('id'); $('.backdrop, #vid'+ $id).animate({'opacity':'.50'}, 300, 'linear'); $('#vid'+ $id).animate({'opacity':'1.00'}, 300, 'linear'); $('.backdrop, #vid'+ $id).css('display', 'block'); }); $('.backdrop').click(function(){ close_box(); }); }); function close_box() { $('.backdrop,.video').animate({'opacity':'0'}, 300, 'linear', function(){ $('.backdrop,.video').css('display', 'none'); }); };
i should mention quite new these languages!
you can use youtube player api iframe embeds. here reference it.
instead of placing iframe
tag, create empty div
id
, script
tag javascript code. code generates iframe
, places on dom, removing created div
, script
tags. allows manipulate player
in script
tag.
here working example in jsfiddle.
p.s. please pay attention "requirements" section.
Comments
Post a Comment