javascript - Replace img with iframe on click of button -
im pretty new js/jquery , need more knowledgeable!
i have had on site , on web cannot find answer myself. i've played around myself limited knowledge cannot figure out next.
what i've got
i have img
when clicked replaced iframe
(youtube video), placeholder/poster, , works below code, found here: how add splash screen/placeholder image youtube video:
<div class="playbutton"></div> <img src="image.jpg" data-video="http://www.youtube.com/videolink"> <script> $('img').click(function(){ var video = '<div class="video-container"><iframe src="'+ $(this).attr('data-video') +'"></iframe></div>'; $(this).replacewith(video); }); </script>
as said - works when image clicked is replaced video.
the problem
i have added play button (currently div
can use img
instead) floating above img
. if click on play button nothing happens (obviously nothing script).
i want play button "trigger" replacing of img
iframe
not have clue add script make happen.
what i'm looking for
i'm looking play button "trigger" when clicked or ideally have both play button , img
"triggers" works if user clicks on image , not play button.
while i've got you...
would able replace iframe
img
again if close button added mix , clicked on?
any appreciated!
dale
this want including close button: here working fiddle: http://jsfiddle.net/anrht/6/
js:
$('.playbutton,img').click(function(){ var video = '<div class="video-container"><iframe src="'+$('img').attr('data-video') +'"></iframe></div>'; $('.video').hide(); $('.tube').html(video); $('.close').show(); }); $('.close').click(function(){ $('.video').show(); $('.tube').empty(); $('.close').hide(); });
html:
<div class="video"> <div class="playbutton">play</div> <img src="http://cdn0.sbnation.com/uploads/chorus_image/image/5372321/battlefield3-screen-12.0_cinema_640.0.jpeg" data-video="http://www.youtube-nocookie.com/embed/u8hvqxkeu8u?&autoplay=1&rel=0&fs=0&showinfo=0&autohide=3&modestbranding=1"> </div> <div class="tube"></div> <div class="close">close x</div>
Comments
Post a Comment