back

Mouse observer

The mouse observer is used to observe mouse movement relative to DOM Elements.

Usage

const myElement = document.getElement('#my-element')
luge.mouseobserver.add(myElement)

Emitter.on('mouseMove', () => {
  const mouse = myElement.luge.mouse

  // Mouse position relative to myElement top left corner
  console.log(mouse.x, mouse.y)

  // Mouse progress inside myElement bounding box
  console.log(mouse.progressX, mouse.progressY)
}, this)

Properties

Observed elements get new properties:

  • luge.mouse.x / luge.mouse.y: a number containing the mouse position relative to the element top left corner in px.
  • luge.mouse.progressX / luge.mouse.progressY: a number containing the mouse progress within the element bounding box (from 0 to 1).

Methods

add(element)

Add an element to the observer.

Parameter Type Description
element HTMLElement DOM element to observe.

remove(element)

Remove an element from the observer.

Parameter Type Description
element HTMLElement DOM element to remove.