2016-08-23 8 views
0

DojoにはmarginBox関数があります。 https://dojotoolkit.org/reference-guide/1.7/dojo/marginBox.htmljQueryのdojoのmarginBox()に相当するものは何ですか?

jQueryの機能に相当するものは何ですか?

+1

私は道場を知らないが、ネイティブのDOM APIで、それはに非常に似ています[getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect)メソッドではなく、ビューポートからの相対的なものであり、静的でない親要素ではありません。これに対して、 'element.offsetLeft'と' element.offsetTop'はjQueryの 'position()'メソッドと全く同じ結果です –

答えて

1

jQueryの関数をいくつか使用して、必要な情報を取得できます。

console.log("Width: " + $('#a1').outerWidth(true)); 
 
console.log("Height: " + $('#a1').outerHeight(true)); 
 
console.log("Top: " + $('#a1').position().top); 
 
console.log("Left: " + $('#a1').position().left);
body { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
#a1 { 
 
    width: 250px; 
 
    height: 150px; 
 
    padding: 10px; 
 
    margin: 15px; 
 
    border: 1px solid gray; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<br /><br /> 
 
<div id="a1"> 
 
    This is a div with margin, padding and border 
 
</div>

関連する問題