• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

Standalone Image on Click YouTube Video

I have a YouTube video on my website that before played shows the preview image that's very pixelated.  I want to put a high resolution image on my website that on click will then play the youtube video, is there a way to do this?
0
Nathan Riley
Asked:
Nathan Riley
  • 2
1 Solution
 
quizwedgeCommented:
You can do something like the following

<img id="high_res_image" src="high_res_image.jpg">
<div id="youtube_video" style="display:none;">
<!-- Put YouTube Video code here -->
</div>

Open in new window


This will show the image and hide the YouTube video. Then, in jQuery you'll need the following:

$( "#high_res_image" ).click(function() {
  $('#high_res_image").hide();
  $(#youtube_video).show();
  $('#youtube_video').('iframe')[0].src += "&autoplay=1";
});

Open in new window


What this will do is hide the high resolution image, show the YouTube div and then add autoplay=1 to the YouTube video iframe to (hopefully) start autoplay. Haven't tested it, but I think it should work in theory.
0
 
Nathan RileyFounder/CTOAuthor Commented:
Hmm...not working for me here is a sample of my setup here on jsfiddle:
http://jsfiddle.net/4qFrr/

Maybe I've mistyped something in my code?
0
 
Nathan RileyFounder/CTOAuthor Commented:
Had to tweak the jquery some:
$( "#high_res_image" ).click(function() {
  $( "#youtube_video" ).show( "slow" );
  $( "#high_res_image" ).hide( "slow" );
});

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now