function offset(el) {
let left = 0
let top = 0
while (el) {
left -= el.offsetLeft
top -= el.offsetTop
el = el.offsetParent
}
return {
left,
top,
}
}
+号求得是 el 到 body 元素的偏移距离
-号是啥玩意.....
1
imherer 2019-12-16 17:08:12 +08:00
不都是求和么?只不过一个正一个负
|