- 以百度搜索框为例
let search = document.getElementById('kw');
let rect = search.getBoundingClientRect();
let bodyRect = document.body.getBoundingClientRect();
let top = rect.top - bodyRect.top
let left = rect.left - bodyRect.left
let search = document.getElementById('kw');
let rect = search.getBoundingClientRect();
let bodyRect = document.body.getBoundingClientRect();
let top = rect.top - bodyRect.top
let left = rect.left - bodyRect.left
本文标题:如何计算元素的top和left
本文链接:https://www.haomeiwen.com/subject/gjftkftx.html
网友评论