Skip to content

collides

collides(a, b): boolean

Defined in: core/dom/geometry.ts:102

Returns true if two rectangles overlap. Rectangles that only touch count as overlapping.

Each side can be an element, which is measured with dimens, or a plain object of width, height, x and y. All four numbers are required on an object: nothing checks them, and a missing one makes the result unreliable.

HTMLElement | ElemDimens

First element or rectangle.

HTMLElement | ElemDimens

Second element or rectangle.

boolean

const box = $q('.box');
const area = { width: 100, height: 300, x: 0, y: 200 };
if (collides(box, area)) {
console.log('Elements are colliding.');
}