嵌入在iframe中的Three.js在iOS 8/9中无休止地增长

Pau*_*son 6 html javascript iframe ios three.js

如果使用iframe将包含Three.js的文件嵌入网页中

<iframe id=viewer src=document-with-threejs.html></iframe>

然后,当在Mobile Safari中查看页面时,iframe的大小会无限增长.在今天发布的iOS 9中,此行为尚未得到纠正.发布此问题和答案,以便Web搜索轻松访问这些信息.

Pau*_*son 8

可以在http://threejs.org/examples/index.html中找到此行为的修复程序.截至2016年7月3日的新版和改进版:

var viewer = document.getElementById( 'viewer' );

// iOS iframe auto-resize workaround

if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {

    viewer.style.width = getComputedStyle( viewer ).width;
    viewer.style.height = getComputedStyle( viewer ).height;
    viewer.setAttribute( 'scrolling', 'no' );

}
Run Code Online (Sandbox Code Playgroud)