当前位置:网站首页>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
边栏推荐
- In Tencent, my trial period summary
- Easycvr development environment startup program reports an error import cycle not allowed solution
- Use of SAP QM inspection points
- Operation and maintenance dry goods | how to improve the business stability and continuity through fault recovery?
- Five minute run through 3D map demo
- SAP hum unbinds Hu from delivery order
- Easyrtc call error `failed to execute'send'on'rtcdatachannel'
- Come on, it's not easy for big factories to do projects!
- Go current limiting component package rate source code analysis
- Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
猜你喜欢

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

puzzle(019.1)Hook、Gear

【二叉数学习】—— 树的介绍
Fault analysis | using --force to batch import data leads to partial data loss

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

Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
![[fault announcement] one stored procedure brings down the entire database](/img/7c/e5adda73a077fe4b8f04b59d1e0e1e.jpg)
[fault announcement] one stored procedure brings down the entire database

Technology is a double-edged sword, which needs to be well kept

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

目标5000万日活,Pwnk欲打造下一代年轻人的“迪士尼乐园”
随机推荐
"Adobe international certification" design white must understand the color theory, absolutely full of dry goods
Just now, we received a letter of thanks from Bohai University.
Differences between JSON objects and JSON strings
Configure PHP development environment in MAC environment: apache+php+mysql
Flutter environment installation & operation
What is the difference between level 1, level 2 and level 3 domain names? How to register domain names
Word cannot copy and paste processing method
Could not read username for xxxxx
In the half year, there were 2.14 million paying users, a year-on-year increase of 62.5%, and New Oriental online launched its private domain
Source code analysis of current limiting component uber/ratelimit
Quick reference table of PHP security configuration maintained by OWASP
From home to Ali, a year for junior students to apply for jobs
Produce kubeconfig with permission control
Fault analysis | using --force to batch import data leads to partial data loss
Easycvr development environment startup program reports an error import cycle not allowed solution
解读AI机器人产业发展的顶层设计
How to build a website with a domain name? Is the domain name very cheap
Kangaroo cloud: the overall architecture and key technical points of building a real-time computing platform based on Flink
Overview of new features in mongodb5.0
Microsoft Security, which frequently swipes the network security circle, gives us some enlightenment this time?