سؤال

أنا أستخدم وظيفة Mootools أكثر "getComputedSize" على عنصر Div الذي تم إنشاؤه ديناميكيًا. إنه يعمل بشكل جيد في 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); 

والنتيجة هي "150" في FF ولكن في Chrome النتيجة هي "NAN".

هل يعرف أي شخص كيفية إصلاح هذا في Chrome دون الحاجة إلى ترميز DIV في HTML؟

شكرا مقدما

أليكس

مُثَبَّت:

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

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

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

حقن العنصر قبل محاولة استخدام هذه الطريقة.

هل كانت مفيدة؟

المحلول

مُثَبَّت:

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

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

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

حقن العنصر قبل محاولة استخدام هذه الطريقة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top