Solved

Standalone Image on Click YouTube Video

Posted on 2014-02-25
3
472 Views
Last Modified: 2014-02-25
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
Comment
Question by:N R
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
quizwedge earned 500 total points
ID: 39887284
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
 
LVL 11

Author Comment

by:N R
ID: 39887376
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
 
LVL 11

Author Closing Comment

by:N R
ID: 39887818
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jquery not working after div reload 4 37
converting document.write() to innerHTML 7 53
Jquery 7 34
selected value 16 26
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question