Get dom elements that hate location encapsulation code _ javascript skills

Source: Internet
Author: User
Are you still worried about offset, scroll, inner, client, screen, and mouse? The header is too big. In addition, different browser methods are not the same. Therefore, it is often a waste of time. So I generated a method for users to obtain such data. Introduction
Solve the problem of getting dom elements in various browsers
Compatibility
Ie 6 7 8 firefox 3.6 chrome 4.0 currently only tests these browsers
Author
Jelle lu QQ: 271412542 Email: idche@qq.com blogs: http://www.cnblogs.com/idche/
Source Code Description
Jquery source code is very helpful to me, and also uses the source code of a classmate called bruce lee. Of course, more resources come from the network.
Function Description
// The jelle (elem) object elem transmits the Object ID or dom object. If the object is a window, the window object is passed.
//. Offset () returns the absolute position of the current object relative to the browser. Return Value = {top: a, left: B };
//. Inner () returns the width and height of the visible area of the current object. The returned value is {Hangzhou H: a, left: B };
//. Scroll () returns the top and left areas of the current object. , Return value = {top: a, left: B };
//. Offparent () returns the top left position of the current object from the parent node. , Return value = {top: a, left: B };
//. Client () returns the available height and width of the current object. Return Value: {width: a, height: B };
//. Screen () returns the available height and width of the current screen. Return Value = {width: a, height: B };
//. Mouse (event) returns the x and y coordinates of the current mouse. If elem is not empty, return the coordinates of elem. Return Value: {x: a, y: B };

Example
// Example: return the width of the visible area of p whose ID is test // jelle ('test'). inner (). width // you can directly lower the width next to it.
Jquery-based source code

The Code is as follows:






Untitled document


Related Article

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.