iPad上的HTML5视频元素不会点亮? [英] HTML5 Video Element on iPad doesn't fire onclick?

查看:167
本文介绍了iPad上的HTML5视频元素不会点亮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML中使用视频元素如下:

I am using the video element in my HTML as following:

<div id="container" style="background:black; overflow:hidden;width:320px;height:240px">
<video style="background:black;display:block" id="vdo" height="240px" width="320px" src="http://mydomain/vid.mp4"></video></div>


在javascript中,我这样做:

And in javascript I am doing this:

var video=document.getElementById('vdo');
var container=document.getElementById('container');
video.addEventListener('click', function(e) {
  e.preventDefault();
  console.log("clicked");
}, false);
container.addEventListener('click', function(e) {
  e.preventDefault();
  console.log("clicked");
}, false);


在桌面safari / chrome一切正常工作。我可以在控制台看到两个点击。但在ipad上没有什么。首先我尝试使用iOS 3.2版,然后将其更新为最新的4.2.1,没有任何成功。
我发现了一个类似的问题 HTML5视频元素不会触发单击或touchstart事件,其中建议不要在视频标签中使用控件我没有使用它。

On desktop safari/chrome everything is working fine. I can see two "clicked" in the console. But on ipad there is nothing. First I tried with iOS versin 3.2, then I updated it to the latest one 4.2.1 without any success.
I found a similar question HTML5 Video Element on iPad doesn't fire onclick or touchstart events? where it suggests not to use controls in video tag and I am not using it.

推荐答案

这是一个很晚的答案,但万一有人想知道。如果您将事件更改为touchstart,它将会起作用。

This is a very late answer, but in case anyone wonders. If you change your event to "touchstart" it will work.

    video.addEventListener('touchstart', function(e) {

这个行为似乎对我来说是随机的,因为点击大部分时间都没有正是为什么和何时

This behavior seems sort of random to me, because click works most of the time. I have not looked into exactly why and when

这篇关于iPad上的HTML5视频元素不会点亮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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