[]用iframe内嵌网页及适配
Laya.init(720, 1280);
String.prototype.format = function()
{
if (arguments.length == 0)
{
return this;
}
for (var str = this, index = 0; index < arguments.length; ++index)
{
str = str.replace("{" + index + "}", arguments[index]);
}
return str;
};
var iframe = laya.utils.Browser.window.document.createElement('iframe');
iframe.setAttribute('src', "http://www.layabox.com/");
iframe.setAttribute('frameborder', 0);
var body = laya.utils.Browser.window.document.getElementsByTagName("body")[0];
body.appendChild(iframe);
//适配处理
var frameWidth = 720 * Laya.stage.clientScaleX;
var frameHeight = 1280 * Laya.stage.clientScaleY;
var styleStr = "position: absolute; left: {0}px; top: {1}px; z-index: 100009;";//laya 的index是100000
var str = styleStr.format((laya.utils.Browser.width - frameWidth) * 0.5, (laya.utils.Browser.height - frameHeight) * 0.5);
this.iframe.setAttribute('width', frameWidth);
this.iframe.setAttribute('height', frameHeight);
this.iframe.setAttribute('style', str);
String.prototype.format = function()
{
if (arguments.length == 0)
{
return this;
}
for (var str = this, index = 0; index < arguments.length; ++index)
{
str = str.replace("{" + index + "}", arguments[index]);
}
return str;
};
var iframe = laya.utils.Browser.window.document.createElement('iframe');
iframe.setAttribute('src', "http://www.layabox.com/");
iframe.setAttribute('frameborder', 0);
var body = laya.utils.Browser.window.document.getElementsByTagName("body")[0];
body.appendChild(iframe);
//适配处理
var frameWidth = 720 * Laya.stage.clientScaleX;
var frameHeight = 1280 * Laya.stage.clientScaleY;
var styleStr = "position: absolute; left: {0}px; top: {1}px; z-index: 100009;";//laya 的index是100000
var str = styleStr.format((laya.utils.Browser.width - frameWidth) * 0.5, (laya.utils.Browser.height - frameHeight) * 0.5);
this.iframe.setAttribute('width', frameWidth);
this.iframe.setAttribute('height', frameHeight);
this.iframe.setAttribute('style', str);
没有找到相关结果
已邀请:
要回复问题请先登录
6 个回复
cuixueying
赞同来自:
liukaijv
赞同来自:
熊猫不是猫~
赞同来自:
152*****366
赞同来自:
zhongming
赞同来自:
1634002484用户
赞同来自: