一、getBoundingClientRect
getBoundingClientRect 得到的 top bottom left right 均是以视窗左上角(0,0)坐标为参照点
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Document</title>
<style>
span {
display: block;
width: 200px;
height: 200px;
background-color: pink;
margin: 20px;
box-sizing: border-box;
}
#target {
background-color: brown;
}
<