I would like to display an image before viewing a youtube video in my page. Is there a way to do this with jquery or a javascript function.
I want to overlay this wi
I am sorry the last solution to your issue was incorrect, well no it wasn't but too complicated for what you wanted.
youtube videos will not play if hidden. so add your embed code and set the autoplay=1 but hide the div and then do the jquery flip on the elements. if you copy the code below and run it it should work (except you have to point it to your jquery library)
<body>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<div id="ytapiplayer2" style="display:none;">
<object width="1280" height="745">
<param name="movie" value="http://www.youtube.com/v/kCfP003Btjw?fs=1&hl=en_US&rel=0&autoplay=1"></param>
<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/kCfP003Btjw?fs=1&hl=en_US&rel=0&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="1280" height="745"></embed>
</object>
</div>
<img src="https://i.qmyimage.com/mgen/global/zGetImageNew.ms?args=%22shpimg4198.jpg%22,425,96,1" id="imageID" />
<script type="text/javascript">
$('#imageID').click(function() {
$('#ytapiplayer2').show();
$('#imageID').hide();
});
</script>
</body>
If using the HTML5 iframe from YouTube, the above won't work as the video will play in the background with autoplay=1 set BEFORE the image is clicked. I instead used .append() to append the iframe after the click on the image so the video would only autoplay after the click event for the image.
<body>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<div id="ytapiplayer2" style="display:none;">
</div>
<img src="https://i.qmyimage.com/mgen/global/zGetImageNew.ms?args=%22shpimg4198.jpg%22,425,96,1" id="imageID" />
<script type="text/javascript">
$('#imageID').click(function() {
$('#ytapiplayer2').show();
$('#ytapiplayer2').append('<iframe width="1130" height="636" src="http://www.youtube.com/embed/YOURVIDEOCODEHERE?autoplay=1" frameborder="0" allowfullscreen></iframe>');
$('#imageID').hide();
});
</script>
</body>
As this could be done pretty easy with the javascript api I have also created this effect with the New iFrame Embedding mode (which i find is pretty sweet). It's really simple