javascript - Mootools getComputedSize 在 Chrome 中不起作用

标签 javascript dom google-chrome mootools mootools-more

我在动态创建的 DIV 元素上使用 Mootools More 函数“getComputedSize”。它在 Firefox 中运行良好,但在 Google Chrome 中运行不正常:

CSS:

.resultBox {
    width: 150px;
    height: 100px;
    position: absolute;
    z-index: 1000;
}

Javascript:

this.resultBox = new Element('div', {
    'class': 'resultBox'
});

console.log(this.resultBox.getComputedSize().width); 

结果在 FF 中是“150”,但在 Chrome 中结果是“NaN”。

有谁知道如何在 Chrome 中修复此问题而无需将 DIV 编码到 html 中?

提前致谢

亚历克斯

固定:

this.resultBox = new Element('div', {
    'class': 'resultBox'
});

this.resultBox.inject(this.container, 'top');

console.log(this.resultBox.getComputedSize().width); 

在尝试使用此方法之前注入(inject)元素。

最佳答案

固定:

this.resultBox = new Element('div', {
    'class': 'resultBox'
});

this.resultBox.inject(this.container, 'top');

console.log(this.resultBox.getComputedSize().width); 

在尝试使用此方法之前注入(inject)元素。

关于javascript - Mootools getComputedSize 在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4286310/

相关文章:

javascript - Chrome 浏览器 - navigator.language 不返回国家代码

c# - 如何使用 HtmlAgilityPack 向 <head> 添加 <link> 或 &lt;meta&gt; 标签?

php - DOM loadhtml提取节点和子节点

javascript - 用于抓取的 headless chrome Nodejs 异步循环

javascript - 为什么我的 API 调用会收到重复的数据,而这些数据本应是随机的?

javascript - Zepto.js 中的 Dom 异常 12

google-chrome - Google 通知上的点击事件

javascript - 使用 Javascript 在 asp.net 页面中添加两个数字

javascript - React/Next.js ,打开对话框后页面滚动卡住

javascript - 如何逐渐放大传单,javascript