我想附加一些事件到我的iPad Web應用程序中的HTML5視頻元素,但他們似乎並沒有射擊?我已經在設備和模擬器上測試了這一點,並得到了相同的結果。然而,這些事件(至少onclick)在桌面Safari中工作正常。我也嘗試換一個div的視頻元素,事件觸發罰款?有沒有人遇到這個問題,並有一個解決辦法的想法?iPad上的HTML5視頻元素不會觸發onclick或touchstart事件?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test video swipe</title>
</head>
<body>
<video src='somevid.mp4' id='currentlyPlaying' width='984' height='628' style='background-color:#000;' controls='controls'></video>
<script>
var theVid = document.getElementById("currentlyPlaying");
theVid.addEventListener('touchstart', function(e){
e.preventDefault();
console.log("touchstart");
}, false);
theVid.addEventListener('click', function(e){
e.preventDefault();
console.log("click");
}, false);
theVid.addEventListener('touchmove', function(e){
console.log("touchmove");
}, false);
theVid.addEventListener('touchend', function(e){
console.log("touchend");
}, false);
theVid.addEventListener('touchcancel', function(e){
console.log("touchcancel");
}, false);
</script>
</body>
</html>
太棒了!工作!我遇到了很多與移動Safari和桌面Safari不兼容的問題。他們中的一些人喜歡在視頻中禁用自動播放功能,但在這些網站上記錄了這些內容,但似乎有大量無證的怪癖或者我敢說錯誤!你知道列出這些差異的資源嗎? – 2010-09-27 14:19:19
我不能使它工作:(你究竟是如何創建視頻元素?我看起來像 and in JS我正在做document.getElementById(」vid「)。addEventListener('click',function(e){e.preventDefault(); alert(」clicked「);}) ;它適用於桌面Safari瀏覽器,但不能在iPad/iPhone的罰款請提出了一些解決方法 – bhups 2011-01-10 10:20:54
@bhups - 如果你有一個問題,問一個問題* *,不要在別人的答案,不同的問題只是評論 – Quentin 2011-01-10 10:50:36