当前位置:网站首页>Get the exact offset of the element
Get the exact offset of the element
2022-07-07 22:21:00 【Belden wind】
adopt getBoundingClientRect obtain ( recommend )
const getOffset = (element: HTMLElement) => {
const elemRect = element.getBoundingClientRect();
const offsetY = elemRect.top + window.scrollY;
const offsetX = elemRect.left + window.scrollX;
return {
left: offsetX,
top: offsetY,
};
};
adopt offsetParent obtain ,( If the element has translate(xx,xx), It will fail
const getOffset = (
element: HTMLElement,
type: 'offsetTop' | 'offsetLeft'
): number => {
let actualOffset = element[type];
let current = element.offsetParent as HTMLElement;
while (current !== null) {
actualOffset += current[type];
current = current.offsetParent as HTMLElement;
}
return actualOffset;
};
边栏推荐
- 大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
- 戴森官方直营店免费造型服务现已开放预约 先锋科技诠释护发造型理念,助力消费者解锁多元闪耀造型
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
- SAR image quality evaluation
- 三元表达式、各生成式、匿名函数
- 怎样写一个增广矩阵到txt文件中
- What is the reason for the abnormal flow consumption of 4G devices accessing the easygbs platform?
- [azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
- Song list 11111
- Write in front -- Talking about program development
猜你喜欢

#DAYU200体验官#MPPT光伏发电项目 DAYU200、Hi3861、华为云IotDA

Use blocconsumer to build responsive components and monitor status at the same time

使用 BlocConsumer 同时构建响应式组件和监听状态

Ternary expressions, generative expressions, anonymous functions

Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
![Restapi version control strategy [eolink translation]](/img/65/decbc158f467ab8c8923c5947af535.png)
Restapi version control strategy [eolink translation]

Open source OA development platform: contract management user manual

648. Word replacement

Validutil, "Rethinking the setting of semi supervised learning on graphs"
![Jerry's about TWS pairing mode configuration [chapter]](/img/fd/dd1e252617d30dd7147dbab25de5b4.png)
Jerry's about TWS pairing mode configuration [chapter]
随机推荐
Programming mode - table driven programming
SAR image quality evaluation
Two methods of calling WCF service by C #
How polardb-x does distributed database hotspot analysis
Welcome to CSDN markdown editor
OpenGL homework - Hello, triangle
OpenGL job coordinate system
Embedded development: how to choose the right RTOS for the project?
NVR硬盤錄像機通過國標GB28181協議接入EasyCVR,設備通道信息不顯示是什麼原因?
【Azure微服务 Service Fabric 】在SF节点中开启Performance Monitor及设置抓取进程的方式
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)
MIT6.S081-Lab9 FS [2021Fall]
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
用语雀写文章了,功能真心强大!
Vs custom template - take the custom class template as an example
The latest Android interview collection, Android video extraction audio
[open source] Net ORM accessing Firebird database
Blender exchange group, welcome to the water group ~
The function is really powerful!
Px4 autonomous flight