Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click the poster image the HTML5 video plays?

Tags:

html

jquery

video

I have an HTML5 video with a poster attribute. I would like to somehow set it up so that you can click on anywhere on the video element (the area of the poster image) and it will fire the play event and start the video? I feel like this is fairly standard practice, but I can not find a way to do this without flash. Any help would be much appreciated.

like image 907
Andrew Avatar asked Mar 11 '11 20:03

Andrew


People also ask

What does the poster parameter do in HTML5 video?

The poster attribute specifies an image to be shown while the video is downloading, or until the user hits the play button. If this is not included, the first frame of the video will be used instead.

How do I view HTML5 video?

The HTML5 video will be viewable in all modern day browsers, such as Internet Explorer, Google Chrome, Safari and Firefox. If you are downloading these browsers for the first time then just make sure you have all the latest updates downloaded for them as well. They usually prompt you automatically about the updates.

Can HTML5 play video?

With the introduction of HTML5, you can now place videos directly into the page itself. This makes it possible to have videos play on pages that are designed for mobile devices, as plugins like Adobe Flash Player don't work on Android or iOS.

Which HTML5 element has a poster attribute?

The HTML <video> poster Attribute is used to display the image while video downloading or when user click the play button.


1 Answers

This is working for me Andrew.

In your html head add this small piece of js:

var video = document.getElementById('video'); video.addEventListener('click',function(){     video.play(); },false); 

Or, just add an onlick attribute directly to your html element:

<video src="your_video" width="250" height="50" poster="your_image" onclick="this.play();"/> 
like image 148
emags Avatar answered Oct 11 '22 23:10

emags