views:

68

answers:

3

Essentially, on page load, I want a video to be hidden behind an image (I guess this can be done with positioning divs).

I would want the video to begin to play when a user clicks on the image the video is hidden behind. This should be possible with a bit of JavaScript/CSS.

What I'm really asking is does anyone know of any examples of this, or would it be possible with some jQuery/Mootools extension...? I would prefer not to use Flash so it works on iPhone/iPad.

Thanks

+2  A: 

This is normally done when embedding Quicktime movies. It can be done directly with the video if you are able to set its poster frame. It is also commonly done by placing an image on the screen in the same place as the video and switching between them. The code could look something like this.

HTML

...

<embed id="video" style="display: none;">...<embed>

<img id="poster" onclick="switchToVideo()">

...

JS

function switchToVideo(){

document.getElementById('video').style.display = "block";

document.getElementById('poster').style.display = "none";

document.getElementById('video').Play();

}

Peter Zich
Thank you - This is a very simple and effective solution. I am using it in conjunction with the YouTube JS API.I would like to investigate using the z-index method too. Though I have a feeling this may not be quite as simple, as the YouTube video should load and call its "onReady" function, which it doesn't do in this case, as it is not being displayed. I'll keep you updated.
Jason
A: 

As you described (I don't know the exact syntax), just place an image with a higher z-level over anything you want to hide and handle an onClick method for it in JavaScript.

Steven
Are you sure that works? Prot0's comment suggests that it won't work with WMV videos and possibly QT videos. Apple's movie trailer sites use the javascript/css hidden/visible technique Peter suggests.
Lèse majesté
You wouldn't actually hide the video explicitly. Just put an image over it.
Steven
That's what I'm saying. A lot of embedded video controls don't respect z-index. That's why you can't put an image over an embedded video or write text over embedded video.
Lèse majesté
A: 

In order for stacking to work with videos you will need to add the wmode variable to the object/embed. Also, to stack you will need to use position: absolute on the element that you want to place on top of the other. Contain them both in a relative container and make the z-index higher on the one that needs to go above.

Here is an example of adding wmode to the video:

<object width="400" height="300">
    <param name="movie" value="" />
    <param name="wmode" value="transparent">
    <!--[if !IE]>-->
    <embed src="" width="400" height="300" wmode="transparent" menu="false">
    <!--<![endif]-->
</object>
Dale
I don't have any WMV videos to try it with, but there is some suggestion that `wmode` alone will not work. But there is a fix using `<param name="WindowlessVideo" value="-1"/>`: http://www.sitepoint.com/forums/showthread.php?t=543926
Lèse majesté