[]HTMLDivElement中图文混排怎么获取实际内容大小
使用HTMLDivElement插入图片,获取不到控件大小,导致与其他控件的间隔错误,影响界面布局
例如:res/image/1.png 像素大小是 32x32
var imageHtml: Laya.HTMLDivElement = new Laya.HTMLDivElement();
imageHtml.innerHTML="<img src='res/image/1.png' />";
console.log("size: " + imageHtml.width + ", " + imageHtml.height);
console.log("contextSize: " + imageHtml.contextWidth + ", " + imageHtml.contextHeight);
Laya.stage.addChild(imageHtml);
上述代码在Laya中运行 正确显示了 图片
控制台输出:
size: 200, 200
contextSize: 0, 0
如何获取真实大小?
例如:res/image/1.png 像素大小是 32x32
var imageHtml: Laya.HTMLDivElement = new Laya.HTMLDivElement();
imageHtml.innerHTML="<img src='res/image/1.png' />";
console.log("size: " + imageHtml.width + ", " + imageHtml.height);
console.log("contextSize: " + imageHtml.contextWidth + ", " + imageHtml.contextHeight);
Laya.stage.addChild(imageHtml);
上述代码在Laya中运行 正确显示了 图片
控制台输出:
size: 200, 200
contextSize: 0, 0
如何获取真实大小?
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
Laya_XS
赞同来自:
Laya_XS
赞同来自: