@blockquote/frontend-utilities
Version:
Utilities for managing the DOM, handling events, and performing various common tasks in frontend development.
13 lines (12 loc) • 553 B
JavaScript
/**
* Checks if a click event occurred inside a given bounding rectangle.
*
* @param {DOMRect} rect - The bounding rectangle, typically obtained from `element.getBoundingClientRect()`.
* @param {PointerEvent} ev - The click event.
* @returns {boolean} True if the click occurred inside the rectangle, false otherwise.
*/
export const isClickInsideRect = (rect, ev) => {
const {top, left, height, width} = rect;
const {clientX, clientY} = ev;
return clientY >= top && clientY <= top + height && clientX >= left && clientX <= left + width;
};