ios - 嵌入 iframe 时的 HTML5 游戏触摸问题

标签 ios css html iframe embed

我正在尝试将 HTML5 游戏嵌入到 iframe 中,以便在 iPad 和 iPhone 等移动设备的浏览器中显示。

如果您直接在 iPad 上访问它们,它们工作正常。

但如果您使用 iframe 嵌入它们,那么当您触摸游戏然后松开时,游戏会暂停。

有没有办法阻止这种 iframe 行为,以便它们按应有的方式运行?

当您停止触摸时似乎失去了焦点,它认为是您的空缺和停顿?

示例

在模拟器中尝试下面的两个示例链接,您会看到问题

我正在使用的代码(基本)

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Game</title>
</head>    
<body>

<div>
  <iframe src="http://static.tresensa.com/madcab/index.html?dst=A0000" frameborder="0" scrolling="no" width="960" height="536"></iframe>
</div>

</body>
</html>

我尝试过的

改变交互类型的CSS样式

<div style="overflow:auto;-webkit-overflow-scrolling:touch;">
    <iframe src="" height="" height=""></iframe>
</div>

JS 防止默认值

<script>
document.ontouchmove = function(e) {
    e.preventDefault();
};
</script>

...都没有帮助

最佳答案

现在遇到同样的问题。似乎只有 Safari 以这种方式在 Google Chrome Samsung Galaxay S4 上运行。

更新: 我认为这个问题无法通过托管游戏的网站来解决。到目前为止,我在深入研究 Material 时发现了什么:如果将其添加到代码中 例如 CSS:

body{
    -ms-touch-action: none;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    }

或/和Javascript

document.addEventListener('ontouchstart', function(e) {e.preventDefault()}, false);
document.addEventListener('ontouchmove', function(e) {e.preventDefault()}, false);

在“iframed 游戏”中,它将起作用并阻止此行为(例如:touchmoves、touchscroll 等使游戏失去焦点的一切)。 但是 iframe 中的所有内容都遵守那里的代码规则,如果我们尝试将其添加到 iframe-grid 中,似乎无法阻止。

我能想到的唯一解决方法是用更高的 z-index 覆盖一个绝对不可见的 div,并尝试向其添加功能。但我认为在这种情况下,游戏将不再对触摸做出响应。 IDK...

关于ios - 嵌入 iframe 时的 HTML5 游戏触摸问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19801461/

相关文章:

iphone - 另一个应用程序可以注册我的自定义 url 方案吗

iphone - 根据其 ID 加入特定的 GKTurnBasedMatch

css - 侧边栏 + 2 个扩展内容 div

html - 如何向 WordPress 选项卡元素添加自定义颜色?

iphone - 具有Facebook Connect的iPhone应用程序的体系结构

iphone - UIImageView 转换缩放

html - Bootstrap Jumbotron 格式问题

php - 使用 Bootstrap 为 `wp list` 类别设置样式

html - 如何使用 HTML 定位 "box"的 div

javascript - 来自数据库的 base.html 中的 Django init 东西