Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "mouse-position"

Index

Type aliases

Vec2

Vec2: object

Type declaration

  • x: number
  • y: number

Functions

elementOffset

  • elementOffset(elem: HTMLElement | ClientRect | DOMRect, ignoreWindowOffset?: boolean, targetBox?: Vec2): Vec2
  • Calculate the offset of element

    Parameters

    • elem: HTMLElement | ClientRect | DOMRect

      element or getBoundingClientRect() result to calculate offset of

    • Default value ignoreWindowOffset: boolean = true

      should the windows scroll position be included in the offset? (false if object is fixed position)

    • Default value targetBox: Vec2 = {x:0,y:0}

      optionally provide an object to mutate with the results (to reduce garbage collection)

    Returns Vec2

Const getWindow

  • getWindow(elem: any): Window
  • Parameters

    • elem: any

    Returns Window

Const isHTMLElement

  • isHTMLElement(elem: any): boolean
  • Parameters

    • elem: any

    Returns boolean

Const isTouchEvent

  • isTouchEvent(c: any): boolean
  • Parameters

    • c: any

    Returns boolean

Const isWindow

  • isWindow(elem: any): boolean
  • Parameters

    • elem: any

    Returns boolean

mousePosition

  • mousePosition(clientX: number, clientY: number, element?: HTMLElement | ClientRect | DOMRect, offset?: Vec2, target?: Vec2): Vec2
  • Calculate the provided x, y values to be relative to the provided elements offset

    Parameters

    • clientX: number

      the x position to transform (event.clientX) from a MouseEvent

    • clientY: number

      the y position to transform (event.clientY) from a MouseEvent

    • Optional element: HTMLElement | ClientRect | DOMRect

      the element to make the coordinate relative to (provide either this or offset)

    • Optional offset: Vec2

      optionally provide the elements offset (reduce work if already calculated)

    • Optional target: Vec2

      optionally provide an object to be mutated with result (reduce garbage collection)

    Returns Vec2

mousePositionFromEvent

  • mousePositionFromEvent(event: MouseEvent | TouchEvent, element?: HTMLElement | ClientRect | DOMRect, offset?: Vec2, target?: Vec2): Vec2
  • Calculate the position of the provided MouseEvent or TouchEvent relative to the provided element

    Parameters

    • event: MouseEvent | TouchEvent

      the MouseEvent or TouchEvent to get coordinate from

    • Optional element: HTMLElement | ClientRect | DOMRect

      the element to make the coordinate relative to

    • Optional offset: Vec2

      optionally provide the elements offset (to reduce work)

    • Optional target: Vec2

      optionally provide an object to be mutated with result (to reduce garbage collection)

    Returns Vec2

Object literals

Const __tmpVec2

__tmpVec2: object

x

x: number = 0

y

y: number = 0