单击 HTML5 视频播放的海报图像? [英] Click the poster image the HTML5 video plays?

查看:23
本文介绍了单击 HTML5 视频播放的海报图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有海报属性的 HTML5 视频.我想以某种方式设置它,以便您可以单击视频元素上的任何位置(海报图像的区域),它会触发播放事件并启动视频?我觉得这是相当标准的做法,但我找不到没有闪光灯的方法.任何帮助将不胜感激.

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.

推荐答案

这对我有用.安德鲁.

在你的 html 头部添加一小段 js:

In your html head add this small piece of js:

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

或者,直接在你的 html 元素中添加一个 onlick 属性:

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();"/>

这篇关于单击 HTML5 视频播放的海报图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆