简体   繁体   English

在iPad和iPhone上滚动到iframe

[英]Scroll over iframe on iPad and iPhone

I have a couple of iFrames in my page, and it is not possible to scroll over those iframes on tablet, phone devices, and in firefox as well. 我的页面中有几个iframe,并且无法在平板电脑,电话设备以及Firefox中滚动这些iframe。 To solve this, I placed a fixed div over the iframe and have the following code to copy the the pointer position (when click happens) and trigger click inside iframe , now the fixed div allows me to scroll over the iFrames and click works too. 为了解决这个问题,我在iframe上放置了一个固定的div,并使用以下代码复制了指针位置(发生单击时)并在iframe内触发了单击,现在固定的div允许我滚动iframe并单击也可以工作。 But when in desktop, even though the click works thanks to this trick, the hover does not work so the buttons and everything else with hover become dead solid. 但是,在桌面环境中,即使通过此技巧进行单击,鼠标悬停也不起作用,因此按钮以及带有悬停的所有其他内容都变得牢不可破。 Is there any better solution for this touch-scrolling issue on iFrames? 对于iFrame上的触摸式滚动问题,是否有更好的解决方案?

This is the code I am using to copying and transferring the position of mouse to the iframe and execute the click (foo = the fixed div over the iframe): 这是我用来将鼠标位置复制并转移到iframe并执行点击的代码(foo = iframe上的固定div):

$('.foo').click(function(event){
    var iframe = $('.frameClass').get(0);
    var iframeDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;

    // Find click position (coordinates)
    var x = event.offsetX;
    var y = event.offsetY;

    // Trigger click inside iframe
    var link = iframeDoc.elementFromPoint(x, y);
    var newEvent = iframeDoc.createEvent('HTMLEvents');
    newEvent.initEvent('click', true, true);
    link.dispatchEvent(newEvent);
});

I have had many problems with the iframe scroll on iPad. 我在iPad上使用iframe滚动时遇到了很多问题。 All the possible answers can be found on this page : http://dev.magnolia-cms.com/~czimmermann/blog/ipad-iframe/iframe1-tall.html 可以在此页面上找到所有可能的答案: http : //dev.magnolia-cms.com/~czimmermann/blog/ipad-iframe/iframe1-tall.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM