当有一个 iframe 覆盖页面内容且没有指针事件时,任何点击都会通过它并由 iframe 下面的元素注册。但出于某种原因,这在 iOS 上的 Safari 中并非如此。我构建了一个简单的 JsFiddle如果你在 PC 上,你可以点击绿色文本,它会显示“Hello World”,但在 iPhone 上,iframe 劫持了点击,没有任何反应。这是故意的吗?如果没有,我可以在某处报告吗?
代码是: HTML
<p onclick="$('#hidden').show()">
Clicking me shows Hello World underneath. But in Safari on iOS the iframe ovalaying me hijacks the clicks even though it has pointer events none
</p>
<p id="hidden" style="display:none">
Hello World!
</p>
<iframe id="iframe" src=""></iframe>
CSS
#iframe {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: orange;
opacity: 0.2;
pointer-events: none;
}
最佳答案
添加一个负的 z-index,例如 z-index: -1000;
,到您的 #iframe
可以解决这个问题。我已经更新了你的 fiddle ,现在可以在 iOS 上使用。
关于html - 带指针事件的 iframe :none hijacks clicks in Safari on iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39533016/