当前位置:网站首页>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;
};
边栏推荐
- Wechat official account oauth2.0 authorizes login and displays user information
- Google SEO external chain backlinks research tool recommendation
- 如何选择合适的自动化测试工具?
- The difference between NPM uninstall and RM direct deletion
- Jerry's manual matching method [chapter]
- npm uninstall和rm直接删除的区别
- Dry goods sharing | devaxpress v22.1 original help document download collection
- NVR hard disk video recorder is connected to easycvr through the national standard gb28181 protocol. What is the reason why the device channel information is not displayed?
- Talk about relational database and serverless
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
猜你喜欢
South China x99 platform chicken blood tutorial
Use json Stringify() to realize deep copy, be careful, there may be a huge hole
Jerry's manual matching method [chapter]
[advanced MySQL] index details (I): index data page structure
cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘
Solve the problem of uni in uni app Request sent a post request without response.
Preparing for the interview and sharing experience
Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
嵌入式开发:如何为项目选择合适的RTOS?
100million single men and women "online dating", supporting 13billion IPOs
随机推荐
Display optimization when the resolution of easycvr configuration center video recording plan page is adjusted
强化学习-学习笔记9 | Multi-Step-TD-Target
Which financial products will yield high returns in 2022?
如何选择合适的自动化测试工具?
How does win11 unblock the keyboard? Method of unlocking keyboard in win11
Latest Android advanced interview questions summary, Android interview questions and answers
Record a garbled code during servlet learning
ByteDance Android interview, summary of knowledge points + analysis of interview questions
Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
Code of "digital image processing principle and Practice (matlab version)" part2[easy to understand]
Overseas agent recommendation
Can I open a stock account directly online now? Is it safe?
Matplotlib drawing interface settings
Use json Stringify() to realize deep copy, be careful, there may be a huge hole
PDF文档签名指南
Attitude estimation (complementary filtering)
How to turn on win11 game mode? How to turn on game mode in win11
OpenGL job coordinate system
Song list 11111
South China x99 platform chicken blood tutorial