【发布时间】:2018-11-17 15:01:01
【问题描述】:
我在 iOS (Safari) 上遇到 iframe 问题。
我们正在通过 iframe 在我们的网页中使用网页 - 它在 PC 和 Android 上看起来很棒,但在 iOS 上整个视图被破坏了,我无法让可滚动的 iframe 在 iOS 上工作了。
我们曾经在 iframe 本身之外(在 div 中)修复 iOS 滚动问题:
overflow: auto;
-webkit-overflow-scrolling: touch;
position: fixed;
不幸的是,这不再有效,因此我们将其删除。 这是iframe 现在的样子:
<div class="nobottommargin">
<p><iframe style="height: 500px; width: 100%; border: none; top: 0; left: 0;" src="https://url.com" scrolling="yes" allowfullscreen="yes" width="320" height="240"></iframe></p>
</div>
关于如何解决此问题或此处可以使用哪些其他替代方案的任何想法?
编辑:我也尝试过,但没有成功:
-
touch-action: auto在 iframe 标签上 -
scrolling="no"在 iframe 标签上 pointer-events: none
编辑 2:滚动现在可以工作,但是在向下滚动时,它会在中间切断我的 iframe。仅在 iOS 上再次出现问题(在 Android 和 PC 上看起来不错)。
这是我遇到的带有 iframe 裁剪错误的有效 iOS 滚动代码:
<div class="scroll-container scroll-ios" style="height:500px;width: 100%; position:relative">
<div class="mainContainer-scroll" style="position:absolute;height:100%;width:100%;min-width:50%;min-height:50%;max-height:500%;top:0;left:0;-webkit-overflow-scrolling: touch !important;overflow-y:scroll !important">
<iframe id="iframe_test" src="url.com" style="height: 100%; width:100%;min-width:100%;" name="myiFrameFix" allowfullscreen="yes" scrolling="yes"> </iframe>
</div>
</div>
编辑 3: 我还尝试过删除所有欺骗浏览器使用 GPU 的 CSS:
-webkit-transform: translateZ(0px);
-webkit-transform: translate3d(0,0,0);
-webkit-perspective: 1000;
不幸的是,这也没有修复 iframe iOS 错误(在 iOS 9 和 11 上尝试过)。
编辑 4: 尝试使用脚本修复 iframe 裁剪问题,使 iframe 的高度与整个主体相同。我又一次失败了。
<script>
$(function() {
var iframe = $("#iframe_test");
iframe.load(function() {
$("body").height(iframe.height());
});
});
</script>
【问题讨论】:
-
这些属性应用于什么选择器?
-
@ChaseIngebritson 你的意思是我们在它不起作用之前使用的修复程序吗?我们把它放在一个额外的滚动容器中。我们也使用了这个:overflow-y:scroll。控制溢出的 div 比使用 iframe 更容易。
<div class="scroll-wrapper"> <iframe src=""></iframe> </div>.scroll-wrapper { -webkit-overflow-scrolling: touch; overflow-y: scroll; /* dimensions and positions were placed here */ } -
试试高度:200px; (像素不是百分比!)对于 nobottommargin !
标签: html ios css iframe scroll