2010-11-26 14 views
2

동적으로 생성 된 DIV 요소에서 Mootools More 함수 "getComputedSize"를 사용하고 있습니다. 그것은 구글 크롬 파이어 폭스에서 잘 작동하지만 :Mootools getComputedSize가 Chrome에서 작동하지 않습니다.

CSS :

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

자바 스크립트 :

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

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

결과는 FF에서 "150"하지만 크롬의 결과는은 「NaN」 .

DIV를 html로 코딩하지 않아도 Chrome에서이 문제를 해결하는 방법을 아는 사람이 있습니까? 사전

알렉스

에서

덕분에 고정 :

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

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

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

이 방법을 사용하기 전에 요소를 주입한다.

+1

먼저 dom에 주입해야합니다. –

+1

FYI는 호출 스택의 끝에,'.width'는'document.defaultView.getComputedStyle (this.resultBox, null) .width' 호출에 의해 채워질 것입니다. 스타일을 계산하려는 요소가 DOM 트리에 없기 때문에 getComputedStyle은 Chrome에서 빈 문자열을 반환하고 Firefox는 질문 한대로 계산하지만 Opera는 생각합니다. 스펙은이 경우 구현이 수행하는 작업에 약간 모호합니다. 도움을 주셔서 감사합니다. http://lists.w3.org/Archives/Public/www-style/2010Apr/0433.html –

+1

을 참조하십시오. 원래 DOM보다 먼저 DOM에 삽입했는데 이제는 훌륭하게 작동합니다. – beingalex

답변

1

는 고정 :

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

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

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

이 방법을 사용하기 전에 요소를 주입한다.

관련 문제