当前位置:网站首页>On BOM and DOM (6): bit value calculation of DOM objects and event objects, such as offsetx/top and clearx
On BOM and DOM (6): bit value calculation of DOM objects and event objects, such as offsetx/top and clearx
2022-06-24 06:35:00 【Army Zhou】
Will always be javascript Of event Object's clientX,offsetX,screenX,pageX I feel dizzy , So I decided to draw a picture to distinguish ( My hand is so sour ....)
event Object location information acquisition
Let's summarize the differences :
event.clientX、event.clientY
The mouse is relative to browser Of the viewable area of the window X,Y coordinate ( Window coordinates ), The viewable area does not include toolbars and scrollbars .IE Events and standard events both define this 2 Attributes
event.pageX、event.pageY
Be similar to event.clientX、event.clientY, But they use document coordinates instead of window coordinates . this 2 Attribute is not a standard attribute , But it has broad support .IE There was no such thing in the incident 2 Attributes .
event.offsetX、event.offsetY
The mouse is relative to the event source element (srcElement) Of X,Y coordinate , Only IE The incident has this 2 Attributes , Standard events have no corresponding properties .
event.screenX、event.screenY
The mouse is relative to the top left corner of the user's display screen X,Y coordinate . Standard events and IE Events define this 2 Attributes
dom Element location information acquisition
client Refers to the visual content of the element itself . barring overflow The folded part , Not including scrollbars 、border, Include padding
obj.clientWidth = (width + padding) // Get the width of the element —— The visible width of the object , Changes with the display size of the window
obj.clientHeight = (height + padding) // The height of the elements
clientTop、clientLeft These two return the thickness of the border around the element , Generally, its value is 0. Because the scroll bar doesn't appear at the top or left
offset Finger offset , Include all display widths taken up by this element in the document . Than client More border.
obj.offsetWidth = width + padding + border // Width of element
obj.offsetHeight = border-width*2+padding-top+height+padding-bottom // Height of element
offsetParent Property returns a reference to an object , This object is a distance call offsetParent The most recent of the parent elements of ( The closest... In the containment hierarchy ), And it has been done CSS Positioned container elements . If the container element does not CSS location , be offsetParent The value of the attribute is the reference of the root element .
- If the parent element of the current element does not have CSS location (position by absolute/relative),offsetParent by body
- If the parent element of the current element has CSS location (position by absolute/relative),offsetParent Take the nearest element in the parent
obj.offsetLeft // Merged height , Element gets the entire layout relative to the parent element , from offsetParent Property specifies the calculated upper position of the parent coordinate
obj.offsetTop // Element relative to the parent element top
scroll Refers to scrolling , Include the actual width that this element does not show , Include padding, Not including scrollbars 、border
scrollWidth Gets the scrolling width of the object , The actual width of the object ;
scrollHeight Get the scrolling height of the object
scrollLeft The width that has been scrolled Sets or gets the distance between the left boundary of the object and the leftmost end of the currently visible content in the window
scrollTop Sets or gets the distance between the top of the object and the top of the visible content in the window
js in getBoundingClientRect
When the scroll position changes ,top and left The attribute value will change immediately ( therefore , Their values are relative to the viewport , Not absolutely ). If you need to get the attribute value positioned relative to the upper left corner of the whole page , Then just give top、left Property value plus the current scroll position ( adopt window.scrollX and window.scrollY), In this way, you can get the value independent of the current scroll position .
Reprint This station article 《 We can talk BOM and DOM(6):dom Object and event Object bit value calculation — Such as offsetX/Top,clentX》, Please indicate the source :https://www.zhoulujun.cn/html/webfront/SGML/xml/2015_1209_353.html
边栏推荐
- The gadgets developed by freshmen are popular. Netizen: my food is good
- How does easyplayer RTSP configure sending heartbeat information to the server?
- What I regret most when I learn programming!
- Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.
- When should I use Apache Druid
- Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
- 10 year old drivers who have been engaged in software testing tell you what type of software is suitable for automation
- 创客教育给教师发展带来的挑战
- When easynvs is deployed on the project site, easynvr cannot view the corresponding channel. Troubleshooting
- SQL server memory management on cloud
猜你喜欢

ServiceStack. Source code analysis of redis (connection and connection pool)

【二叉数学习】—— 树的介绍

Manual for automatic testing and learning of anti stepping pits, one for each tester
![Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.](/img/2c/d04f5dfbacb62de9cf673359791aa9.png)
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.
Oracle case: ohasd crash on AIX

【二叉树】——二叉树中序遍历

基于三维GIS系统的智慧水库管理应用

puzzle(019.1)Hook、Gear

云上本地化运营,东非第一大电商平台Kilimall的出海经

The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales
随机推荐
Come on, it's not easy for big factories to do projects!
Provide SFTP connection for Amazon S3
How to choose CMS website system for website construction
Interpreting the new features of Appstore: Customizing product pages and a/b test tools
[5 minutes to play lighthouse] take you to the light kubernetes release k3s
Operation and maintenance dry goods | how to improve the business stability and continuity through fault recovery?
Flutter environment installation & operation
Flexible use of distributed locks to solve the problem of repeated data insertion
Domain name, resolution, SSL certificate product selection
Discussion on NFT Technology
Centos7 deploying mysql-5.7
Easyscreen live streaming component pushes RTSP streams to easydarwin for operation process sharing
Coding and codesign: make design and development easier
CLB unable to access / access timeout troubleshooting
When easynvs is deployed on the project site, easynvr cannot view the corresponding channel. Troubleshooting
What is Druid
In Tencent, my trial period summary
Neighbor vote: use proximity voting to optimize monocular 3D target detection (ACM mm2021)
The 2021 Tencent digital ecology conference landed in Wuhan, waiting for you to come to the special session of wechat with low code
Distributed cache breakdown