Coordinates of page elements

Source: Internet
Author: User

JavaScript (retrieve or set the width, height, and coordinates of HTML elements)
Settings:
View plaincopy to clipboardprint?
document. getelementbyid ('id '). style. width = value
document. getelementbyid ('id '). style. height = value
document. getelementbyid ('id '). style. top = value
document. getelementbyid ('id '). style. left = value
document. getelementbyid ('id '). style. width = value
document. getelementbyid ('id '). style. height = value
document. getelementbyid ('id '). style. top = value
document. getelementbyid ('id '). style. left = value

Obtain:
View plaincopy to clipboardprint?

Value = Document. getelementbyid ('id'). offsetleft
Value = Document. getelementbyid ('id'). offsettop
Value = Document. getelementbyid ('id'). offsetwidth
Value = Document. getelementbyid ('id'). offsetheight

Value = Document. getelementbyid ('id'). offsetleft
Value = Document. getelementbyid ('id'). offsettop
Value = Document. getelementbyid ('id'). offsetwidth
Value = Document. getelementbyid ('id'). offsetheight

View plaincopy to clipboardprint?
<SCRIPT>
Function findposition (oelement)
{
VaR X2 = 0;
VaR y2 = 0;
VaR width = oelement. offsetwidth;
VaR Height = oelement. offsetheight;
Alert (width + "=" + height );
If (typeof (oelement. offsetparent )! = 'Undefined ')
{
For (VAR posx = 0, Posy = 0; oelement = oelement. offsetparent)
{
Posx + = oelement. offsetleft;
Posy + = oelement. offsettop;
}
X2 = posx + width;
Y2 = posy + height;
Return [posx, Posy, X2, y2];

} Else {
X2 = oelement. x + width;
Y2 = oelement. Y + height;
Return [oelement. X, oelement. Y, X2, y2];
}
}
</SCRIPT>
<SCRIPT>
Function findposition (oelement)
{
VaR X2 = 0;
VaR y2 = 0;
VaR width = oelement. offsetwidth;
VaR Height = oelement. offsetheight;
Alert (width + "=" + height );
If (typeof (oelement. offsetparent )! = 'Undefined ')
{
For (VAR posx = 0, Posy = 0; oelement = oelement. offsetparent)
{
Posx + = oelement. offsetleft;
Posy + = oelement. offsettop;
}
X2 = posx + width;
Y2 = posy + height;
Return [posx, Posy, X2, y2];

} Else {
X2 = oelement. x + width;
Y2 = oelement. Y + height;
Return [oelement. X, oelement. Y, X2, y2];
}
}
</SCRIPT>

View plaincopy to clipboardprint?



This is a layer. This is a layer.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.