Skip to content
Huey
GitHub

DOM Utilities

Helper functions for working with the DOM, positioning, and events.

Get the current scroll position of the page.

getScrollXY(): { x: number, y: number }

Returns an object with x and y scroll coordinates.

Get an element’s absolute position relative to the document.

getAbsolutePosition(element: HTMLElement): { x: number, y: number }

Returns the element’s coordinates accounting for scroll position.

Extract page coordinates from mouse or touch events.

getPageXYFromEvent(event: MouseEvent | TouchEvent): { x: number, y: number }

Normalizes mouse and touch events to return consistent page coordinates.

import { getAbsolutePosition, getPageXYFromEvent } from 'huey/utils'
const element = document.querySelector('.color-picker')
const position = getAbsolutePosition(element)
element.addEventListener('mousedown', (e) => {
const { x, y } = getPageXYFromEvent(e)
// Handle interaction
})