开发者

bottom left & bottom right of HTML element

How could I get bottom left x-开发者_如何转开发y & bottom right x-y of any HTML element? I wanted to assign it to another <div></div>


Your element will need an ID (or some other way to grab it from the DOM).

In raw Javascript, for the bottom left X coordinate:

var obj = document.getElementById('yourElement');  // same as $('#yourElement')
var bottomLeftX = obj.offsetTop + obj .offsetHeight;


Use jQuery position() function:

var element = $("#element");
var width = element.width();
var height = element.height();
var position = element.position();

var bottomLeftX = position.left;
var bottomLeftY = position.top + height;

var bottomRightX = position.left + width;
var bottomRightY = position.top + height;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜