dom/doElementsOverlap

Compares two DOM elements position and checks whether they overlap.

Source:

Methods

(static) doElementsOverlap(element1, element2) → {boolean}

Source:
Example
import { doElementsOverlap } from '@untemps/utils/dom/doElementsOverlap'

const element1 = document.createElement('div')
element1.style = 'width: 140px; height: 140px; position: absolute; background-color: red;'
document.body.appendChild(element1)

const element2 = document.createElement('div')
element2.style = 'width: 130px; height: 130px; position: absolute; background-color: green;'
document.body.appendChild(element2)

const element3 = document.createElement('div')
element3.style = 'width: 130px; height: 130px; left: 250px; top: 250px; position: absolute; background-color: blue;'
document.body.appendChild(element3)

doElementsOverlap(element1, element2) // true
doElementsOverlap(element1, element3) // false
Parameters:
Name Type Description
element1 HTMLElement

The first DOM element to compare.

element2 HTMLElement

The second DOM element to compare.

Returns:

true if the two DOM elements overlap.

Type
boolean