【发布时间】:2013-02-21 08:09:15
【问题描述】:
我在我的移动启用网站(此处使用 iPhone)上使用 iScroll 在 div 内滚动。
在这个 div 中,我有一个固定高度的 iframe,如下所示:
<body>
<div id="iscroller">
<iframe id="theIframe"></iframe>
Other stuff
</div>
</body>
现在,在 div 内滚动时,一切正常,但当滚动手势从 iframe 开始时,我无法滚动。
问题在这里描述得很好:https://github.com/cubiq/iscroll/issues/41
因此,我通过将pointer-events:none 应用于 iframe 来使用该帖子中的 css 解决方法。
现在滚动效果很好但是我无法单击 iframe 中定义的任何链接,因为 iframe 上的所有点击/触摸事件似乎都因pointer-events: none 而被阻止。
所以,我想:
“好的,当用户滚动时,我需要
pointer-events:none。如果他是 不滚动(而是点击),我必须设置pointer-events:auto为了让点击/触摸事件通过。”
所以我这样做了:
CSS
#theIframe{pointer-events:none}
JavaScript
$("#theIframe").bind("touchstart", function(){
// Enable click before click is triggered
$(this).css("pointer-events", "auto");
});
$("#theIframe").bind("touchmove", function(){
// Disable click/touch events while scrolling
$(this).css("pointer-events", "none");
});
即使添加这个也不起作用:
$("#theIframe").bind("touchend", function(){
// Re-enable click/touch events after releasing
$(this).css("pointer-events", "auto");
});
无论我做什么:滚动不起作用或单击 iframe 内的链接不起作用。
不起作用。有什么想法吗?
【问题讨论】:
标签: ios html iframe scroll iscroll