我在我的移動啓用網站(使用iPhone)上使用iScroll在div內滾動。iframe阻止移動Safari上的iScroll滾動
在這個這個div,我有一個固定的高度這樣的iframe:現在
<body>
<div id="iscroller">
<iframe id="theIframe"></iframe>
Other stuff
</div>
</body>
,而專區內滾動,一切正常,但是當滾動姿態開始於我不能滾動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中的鏈接都不起作用。
不起作用。有任何想法嗎?
有沒有其他方法可以做到這一點?這是一個聰明的方法來做到這一點,但我沒有控制iframe,如果它確實改變了即時通訊的螺絲,謝謝隊友:) – jycr753 2013-06-18 21:37:20
@ jycr753如果你的用戶不需要點擊iframe中的鏈接,你可以使用而不是css屬性'pointer-events:none'。 – Timo 2013-06-20 08:51:30
感謝我的讚賞 – jycr753 2013-06-20 08:53:32