JavaScript 碰撞检测-动画

1function konck(node1, node2) {
2  const l1 = node1.offsetLeft
3  const r1 = node1.offsetLeft + node1.offsetWidth
4  const t1 = node1.offsetTop
5  const b1 = node1.offsetTop + node1.offsetHeight
6
7  const l2 = node2.offsetLeft
8  const r2 = node2.offsetLeft + node2.offsetWidth
9  const t2 = node2.offsetTop
10  const b2 = node2.offsetTop + node2.offsetHeight
11
12  if (l2 > r1 || r2 < l1 || t1 > b2 || t2 > b1)
13    return false
14  else
15    return true
16}