问题描述:

setInterval(function() {

var divPosition = $('div').position();

console.log('X: ' + divPosition.left + ", Y: " + divPosition.top");

}, 500);

So I can get the x and y position of this div. left/top but it's a square div on the page. I'm also tracking a section tag that flies around the page, I want to basically do if (_thesectiontag_.left == _thesquarediv_.left || _thesectiontag_.top == _thesquarediv_.top) ... do something so if the section tag is within the div coordinates on the page do something.

But I need to get the full dimensions of the square to be able to do that. I'm a bit lost on where to start and how to go about it.

Can anyone offer some help? Thank you!

网友答案:

Use this two code :

For the Width and Height includes padding :

var Height = document.getElementById('square').clientHeight;

var Width = document.getElementById('square').clientWidth;

For the Width and Height includes padding, scrollBar and borders :

var Height = document.getElementById('square').offsetHeight;

var Width = document.getElementById('square').offsetWidth;
网友答案:
$('div').height($('div').width());
相关阅读:
Top