当前位置:网站首页>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;
};
边栏推荐
- Reinforcement learning - learning notes 9 | multi step TD target
- Jerry's test box configuration channel [chapter]
- Talk about relational database and serverless
- EasyCVR配置中心录像计划页面调整分辨率时的显示优化
- Remember that a development is encountered in the pit of origin string sorting
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
- 解决uni-app中uni.request发送POST请求没有反应。
- Why can't win11 display seconds? How to solve the problem that win11 time does not display seconds?
- 嵌入式开发:如何为项目选择合适的RTOS?
- Jerry's manual matching method [chapter]
猜你喜欢
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?
NVR硬盘录像机通过国标GB28181协议接入EasyCVR,设备通道信息不显示是什么原因?
Win11如何解禁键盘?Win11解禁键盘的方法
The whole network "chases" Zhong Xuegao
South China x99 platform chicken blood tutorial
Embedded development: how to choose the right RTOS for the project?
648. Word replacement
【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)
Talk about relational database and serverless
[JDBC Part 1] overview, get connection, CRUD
随机推荐
The cyberspace office announced the measures for data exit security assessment, which will come into force on September 1
【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
Px4 autonomous flight
What is the reason for the abnormal flow consumption of 4G devices accessing the easygbs platform?
PKPM 2020 software installation package download and installation tutorial
海外代理推荐
【Azure微服务 Service Fabric 】在SF节点中开启Performance Monitor及设置抓取进程的方式
[open source] Net ORM accessing Firebird database
戴森官方直营店免费造型服务现已开放预约 先锋科技诠释护发造型理念,助力消费者解锁多元闪耀造型
How to realize the movement control of characters in horizontal game
NVR硬盘录像机通过国标GB28181协议接入EasyCVR,设备通道信息不显示是什么原因?
建立自己的网站(18)
How to quickly check whether the opening area ratio of steel mesh conforms to ipc7525
如何实现横版游戏中角色的移动控制
DBSync新增对MongoDB、ES的支持
客户案例|华律网,通过观测云大幅缩短故障定位时间
Jerry's about TWS channel configuration [chapter]
How to choose the appropriate automated testing tools?
【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)
OpenGL homework - Hello, triangle