当前位置:网站首页>Element calculation distance and event object
Element calculation distance and event object
2022-04-23 17:41:00 【KK should continue to work hard】
Element calculation distance and event Event object
Elements
1. offsetLeft/offsetTop
The current element is left relative to the parent element / Offset of upper edge . Read-only property , The parent element cannot be static. If the current element is fixed location , Returns the distance between the element and the window .
2. style.left/style.top
The current element is left relative to the parent element / Offset of upper edge .
Be careful
offsetLeft/offsetTop And style.left/style.top The difference between :
- offset Is a read-only property ,style.left Are readable and writable properties ;
- offset The return value is Number type , The decimal will be rounded off ,style.left The return value is string type ( for example :100px);
- style.left Must be in html Defined in label , If in style perhaps css Invalid definition in file , Returns an empty string
3. offsetHeight/offsetWidth
The height of the current element / Width .offset value = content + padding + border, barring margin
4. style.height/style.width
The height of the current element / Width .style value = content + padding, barring border and ,margin
Be careful
offsetHeight/offsetWidth And style.height/style.width The difference between :
- offset Is a read-only property ,style Are readable and writable properties ;
- offset The return value is Number type , The decimal will be rounded off ,style.left The return value is string type ( for example :100px);
- offset Yes border,style barring border;
- style Must be in html Defined in label , If in style perhaps css Invalid definition in file , Returns an empty string
- If the element has no height / Width ,offset The height will be automatically obtained according to the content / Width ,style Returns an empty string
5. clientWidth/clientHeight
The width of the current element / Height .client value = content + padding, barring border、margin And scroll bars
6. scrollWidth/scrollHeight
Roll width / Height .scroll = content + padding, Excluding borders . Read-only property , When there is no scroll bar, it is equivalent to clientWidth/clientHeight
7. scrollTop/scrollLeft
Scroll bar scroll distance upper edge / The distance . Readable and writable properties .
8. innerWidth/innerHeight
- window.innerWidth/window.innerHeight:
① The width of the document display area of the window / Height ,inner value = content + padding, Excluding the menu bar 、 Scroll bar, etc ;
② Read-only property ;
③IE9 The following is not supported , Processing compatibility :
var w=window.innerWidth || document.documentElement.clientWidt || document.body.clientWidth;
9. outerWidth/outerHeight
- window.outerWidth/window.outerHeight:
① Width of window / Height ,outer value = content + padding + border, If outerWidth(true) when ,outer value = content + padding + border + margin;
② Read-only property , Include menu bar 、 Scroll bar
event Event object
1. e.offsetX/e.offsetY
The horizontal distance between the mouse click position and the trigger event object / Vertical distance
2. e.clientX/e.clientY
The horizontal distance of the mouse click position relative to the visible area of the browser / Vertical distance , Not including scrollbars
3. e.pageX/e.pageY
The horizontal distance of the mouse click position relative to the visible area of the browser / Vertical distance , Including scrollbars
4. e.screenX/e.screenY
The mouse click position is relative to the left of the computer screen / The distance above
5. e.movementX/e.movementY
When an object moves , The horizontal distance between the current moving position and the previous moving position / Vertical distance
6. layerX/layerY
Commonly used in Firefox browser , Act on offsetX/offsetY identical

Reference article :https://juejin.cn/post/6883353218319908871
版权声明
本文为[KK should continue to work hard]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230551363353.html
边栏推荐
- 1217_ Generating target files using scons
- 嵌入式系统中,FLASH中的程序代码必须搬到RAM中运行吗?
- Allowed latency and side output
- C dapper basically uses addition, deletion, modification and query transactions, etc
- Some questions some questions some questions some questions
- Simulation of infrared wireless communication based on 51 single chip microcomputer
- Perception of linear algebra 2
- Low code development platform sorting
- 402. Remove K digits - greedy
- Understanding of RPC core concepts
猜你喜欢
![[logical fallacy in life] Scarecrow fallacy and inability to refute are not proof](/img/71/14a17128dbe0f02edb4db3da479ef2.jpg)
[logical fallacy in life] Scarecrow fallacy and inability to refute are not proof

Future 用法详解

Index: teach you index from zero basis to proficient use
![Using quartz under. Net core -- job attributes and exceptions of [4] jobs and triggers](/img/ec/43dddd18f0ce215f0f1a781e31f6a8.png)
Using quartz under. Net core -- job attributes and exceptions of [4] jobs and triggers

470. 用 Rand7() 实现 Rand10()
![SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]](/img/60/e4d47d458dd98a0c6ba51874e07c30.png)
SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]

MySQL进阶之索引【分类,性能分析,使用,设计原则】
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]

超分之TDAN

102. Sequence traversal of binary tree
随机推荐
C语言程序设计之函数的构造
92. Reverse linked list II byte skipping high frequency question
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
Advantages and disadvantages of several note taking software
2021长城杯WP
Excel quickly and automatically fills the contents of a row on a blank cell
239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
958. 二叉树的完全性检验
Type judgment in [untitled] JS
If you start from zero according to the frame
Understanding of RPC core concepts
Write a regular
41. The first missing positive number
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
基于51单片机红外无线通讯仿真
Compare the performance of query based on the number of paging data that meet the query conditions
31. Next arrangement
编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
Use of five routing guards
1217_使用SCons生成目标文件