2017-02-02 12 views
0

나는 살펴 보았다 : Understanding offsetWidth, clientWidth, scrollWidth and -Height, respectively의 offsetWidth는 : 다른해야하지만, 같은

그러나 그것은 사실이 아니다. 예를 들어,

.main { 
    width: 400px; 
    overflow: visible; 
} 

.main table { 
    width: 600px; 
} 

<div class="main"> 

    <table> 
     <thead><tr><th>Foo</th><th>Bar</th></tr></thead> 
     <tbody> 
       <tr><td>Row1</td><td>Hello</td></tr> 
       <tr><td>Row2</td><td>World</td></tr> 
     </tbody> 

    </table> 

</div> 


--------------------------------------- 
|main         | 
|  ---------------------------------------------------- 
|  | table           | 
|  ---------------------------------------------------- 
|          | 
|          | 
--------------------------------------- 

주 div 요소의 offsetWidth와 scrollWidth는 모두 400입니다. 각각 400과 600이어야합니다.

답변

0

나를 위해 일하는 것처럼 보입니까?

http://codepen.io/anon/pen/EZEzGB

alert("Scrollwidth: " + document.getElementById('main').scrollWidth + "OffsetWidth: " + document.getElementById('main').offsetWidth); 

당신은 잘못된 값을 반환 사용하고 있습니까?