sencha touch :: how to create a panel for website-preview inside iFrame

烂漫一生 提交于 2019-12-06 03:13:24
Okendoken

I spent two days fighting with the same problem. It seems that finally I found a solution.

The first thing you should try is to use new built-in feature introduced in iOS 5.

-webkit-overflow-scrolling:touch;

You need to wrap your iframe with div, something like:

...
this.html = '<div style="-webkit-overflow-scrolling:touch; height: 500px; overflow: auto;"><iframe .../></div>'
...

If it doesn't work (in my case it worked only first time) then you can try to handle touch events by yourself. Let's say you have the following structure in html:

<div id="wrapper">
    <iframe id="my-iframe" .../>
</div>

to make iframe scrollable you need to add this JS

var startY = 0;
var startX = 0;
var ifrDocument = document.getElementById("my-iframe").contentWindow.document;
ifrDocument.addEventListener('touchstart', function (event) {
    window.scrollTo(0, 1);
    startY = event.targetTouches[0].pageY;
    startX = event.targetTouches[0].pageX;
});
ifrDocument.addEventListener('touchmove', function (event) {
    event.preventDefault();
    var posy = event.targetTouches[0].pageY;
    var h = document.getElementById("wrapper");
    var sty = h.scrollTop;

    var posx = event.targetTouches[0].pageX;
    var stx = h.scrollLeft;
    h.scrollTop = sty - (posy - startY);
    h.scrollLeft = stx - (posx - startX);
    startY = posy;
    startX = posx;
});

Source of the second solution is here

The only way I got this to work was by nesting the <iframe> in 2 panels, but this will probably only work if you know the dimensions of the document in the <iframe>, I also placed a transparent <div> over the <iframe> so the touch events still trigger the "scroll events"

root = new Ext.Panel({
   fullscreen: true,
   layout: 'card',
   version: '1.1.1',
   scroll: false,
   dockedItems: [{ xtype: 'toolbar', title: 'hello'}],
   items: [{
       xtype: 'panel',
       scroll: 'both',
       items: [{
           id: 'iframe',
           layout: 'vbox',
           width: '1200px',
           height: '1000px',
           html: ['<div style="width:1200px;height:1000px;position:fixed;top:0;left:0;background-color:Transparent;float:left;z-index:99;"></div>',
                  '<iframe style="position:fixed;top:0;left:0;float:left;z-index:1;" width="1200px" height="1000px" src="http://google.com/"></iframe>']
       }]
    }]
});

So using your code:

this.items = [{
               id: 'iframe',
               layout: 'vbox',
               width: '1200px',
               height: '1000px',
               html: ['<div style="width:1200px;height:1000px;position:fixed;top:0;left:0;background-color:Transparent;float:left;z-index:99;"></div>',
                      '<iframe style="position:fixed;top:0;left:0;float:left;z-index:1;" width="1200px" height="1000px" src="' this.theLink + '"></iframe>']
           }]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!