2017-02-02 13 views
0

なければならない私が見てきました: Understanding offsetWidth, clientWidth, scrollWidth and -Height, respectivelyoffsetWidth:異なることが、同じ

しかし、それはそうではありません。たとえば、

.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); 

あなたはそれが間違った値を返している何を使用していますか?

関連する問題