iOS移动:在可滚动的父级内滚动iFrame

Ske*_*ets 6 html css iframe mobile-safari ios

我在移动iOS Safari中遇到了一个问题,当在iFrame内部拖动时,在包含iFrame的div中滚动是不可能的:

#outside{
height: 400px;
width: 200px;
background: blue;
overflow: scroll;
}

.space{
  height: 200px;
  width: 200px;
  background: red;
}

iframe{
height: 1000px;
width: 200px;
background-color: green;
}
Run Code Online (Sandbox Code Playgroud)
The green section is the iFrame.... Scrolling on the green section in iOS mobile is the issue

<div id="outside">
<div class="space"></div>
<iframe>

</iframe>
<div class="space"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

因此,在iFrame上拖动时,由于它没有滚动,因此它应该滚动父页面,而是滚动整个页面.

这个bug有任何已知的解决方法吗?它已经在Android上运行了.

And*_*hiu 4

将你的<iframe>s 放入包装纸中-webkit-overflow-scrolling: touch;

.iContainer {
  -webkit-overflow-scrolling: touch;
}
Run Code Online (Sandbox Code Playgroud)

#outside {
  height: 400px;
  width: 200px;
  background: blue;
  overflow: scroll;
}

.space {
  height: 200px;
  width: 200px;
  background: red;
}

iframe {
  height: 1000px;
  width: 200px;
  background-color: green;
  border: none;
  display:block;
}

iContainer {
  -webkit-overflow-scrolling: touch;
}
Run Code Online (Sandbox Code Playgroud)
The green section is the iFrame.... Scrolling on the green section in iOS mobile is the issue

<div id="outside">
  <div class="space"></div>
  <div class="iContainer">
    <iframe>
    </iframe>
  </div>
  <div class="space"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

特别注意:position:relative与on结合使用会<body>导致 IoS 设备有时会阻止滚动。让它完全从“弹跳”状态恢复可以修复它,但仍然感觉错误和有问题。因此,请确保您的或上
没有任何设置。最近我花了一些时间来调试这个。position<body><html>

  • 哈哈 - 实际上,它适用于目前移动 iOS 浏览器之外的所有浏览器。在 iOS 移动设备上,如果我在容器上有“-webkit-overflow-scrolling: auto;”,在 iFrame 上有“pointer-events: none;”,它就可以工作,但这个解决方案对我不起作用,因为 iFrame 包含可变内容通常包含需要工作的链接。:P 我会继续寻找可能的解决方案。您的回答帮助我理解了 iOS 移动浏览器的一些奇怪行为。 (4认同)
  • 我认为在未来十年内您将无法在所有设备上滚动包含“&lt;iframe&gt;”的模式。我们可能已经在月球上行走过,但人类能做的事情是有限的。而上面的就是其中之一。归根结底,所有浏览器都遵守网络标准。恕我直言,这不会太快发生。 (2认同)