Namespace: CursorPos

CursorPos

An observable module for acquiring the current mouse cursor coordinates.
Source:

Example

SSC.CursorPos.init();
SSC.CursorPos.addObserver((coords) => {
    console.log(coords.x, coords.y);
});

// Get the cursor position outside of an observer:
console.log(SCC.CursorPos.x, SSC.CursorPos.y);

Members

(static) x :number

The X value of the current cursor position.
Type:
  • number
Source:

(static) y :number

The Y value of the current cursor position.
Type:
  • number
Source:

Methods

(static) addObserver(observer)

Add an observer function or object.
Parameters:
Name Type Description
observer mouseMoveObserverFn | MouseMoveObserver The observer to be notified when the cursor position changes
Source:

(static) getFromEvent(ev) → {Coordinates}

Fetch the mouse cursor coordinates from the given mouse event.
NOTE: The module does not need to be init'ed to use this function.
Parameters:
Name Type Description
ev MouseEvent The mouse event to read the coordinates from
Source:
Returns:
The mouse cursor coordinates
Type
Coordinates

(static) init()

Start to acquire the cursor position.
This function must be called once before the cursor coordinates can be read out via observer or SSC.CursorPos.x / SSC.CursorPos.y.
Source:

(static) removeObserver(observer)

Remove the given observer from the observer list.
Parameters:
Name Type Description
observer mouseMoveObserverFn | MouseMoveObserver The observer function or object to remove
Source: