0
道場有marginBox功能: https://dojotoolkit.org/reference-guide/1.7/dojo/marginBox.html。什麼是jQuery相當於dojo的marginBox()?
什麼是該功能的jQuery的等價物?
道場有marginBox功能: https://dojotoolkit.org/reference-guide/1.7/dojo/marginBox.html。什麼是jQuery相當於dojo的marginBox()?
什麼是該功能的jQuery的等價物?
你可以使用幾個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>
我不知道道場,但在本地DOM API,它看起來非常相似[getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect)方法,除了它是相對於視口,而不是任何非靜態父元素。爲此,您有'element.offsetLeft'和'element.offsetTop',這與使用jQuery'position()'方法的結果完全相同 –