当前位置:网站首页>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;
};
边栏推荐
- The difference between NPM uninstall and RM direct deletion
- 建立自己的网站(18)
- The function is really powerful!
- Tsconfig of typescript TS basics JSON configuration options
- Display optimization when the resolution of easycvr configuration center video recording plan page is adjusted
- [open source] Net ORM accessing Firebird database
- Relationship between URL and URI
- Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
- [open source] Net ORM accessing Firebird database
- Win11时间怎么显示星期几?Win11怎么显示今天周几?
猜你喜欢
![Jerry's about TWS channel configuration [chapter]](/img/94/fde5054fc412b786cd9864215e912c.png)
Jerry's about TWS channel configuration [chapter]
![VTOL in Px4_ att_ Control source code analysis [supplement]](/img/7a/4ce0c939b9259faf59c52da2587693.jpg)
VTOL in Px4_ att_ Control source code analysis [supplement]

Time standard library

How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525

Matplotlib drawing interface settings

Embedded development: how to choose the right RTOS for the project?

OpenGL configuration vs2019

Node:504 error reporting

应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设

Vs custom template - take the custom class template as an example
随机推荐
L'enregistreur de disque dur NVR est connecté à easycvr par le Protocole GB 28181. Quelle est la raison pour laquelle l'information sur le canal de l'appareil n'est pas affichée?
Pdf document signature Guide
Use blocconsumer to build responsive components and monitor status at the same time
The essence of analog Servlet
Automatic classification of defective photovoltaic module cells in electronic images
The whole network "chases" Zhong Xuegao
SAR影像质量评估
NVR硬盤錄像機通過國標GB28181協議接入EasyCVR,設備通道信息不顯示是什麼原因?
Jerry's fast pairing does not support canceling pairing [article]
An in-depth understanding of fp/fn/precision/recall
[azure microservice service fabric] how to transfer seed nodes in the service fabric cluster
Write in front -- Talking about program development
Overseas agent recommendation
Two methods of calling WCF service by C #
PKPM 2020 software installation package download and installation tutorial
Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘
Which futures company is the safest to open a futures account?
Display optimization when the resolution of easycvr configuration center video recording plan page is adjusted
How to write an augmented matrix into TXT file
VTOL in Px4_ att_ Control source code analysis [supplement]