如何计算元素的top和left
2018-04-11 本文已影响0人
东方灵将
- 以百度搜索框为例
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