Skip to content

Mouse

Bindings for @solid-primitives/mouse.

MouseSourceType

Type: StringEnum

  • Mouse
  • Touch

Position

Type: POJO

  • x: int
  • y: int

MousePosition

Type: POJO

  • x: int
  • y: int
  • sourceType: MouseSourceType option

MousePositionInside

Type: POJO

  • x: int
  • y: int
  • sourceType: MouseSourceType
  • isInside: bool

PositionRelativeToElement

Type: POJO

  • x: int
  • y: int
  • isInside: bool
  • top: int
  • left: int
  • width: int
  • height: int

Bindings

MemberDesc
makeMousePositionListenerListens for changes to the mouse or touch position on the target. Returns a function that removes the listeners.
makeMouseInsideListenerListens for the mouse or touch entering or leaving the target. Returns a function that removes the listeners.
getPositionToElementTurns a position relative to the page into a position relative to an element.
getPositionInElementLike getPositionToElement, but clamped to the element's bounds.
getPositionToScreenTurns a position relative to the page into a position relative to the screen.
createMousePositionA reactive object with the current mouse position on the page. The target defaults to window, and can be an accessor.
useMousePositioncreateMousePosition on window, as a singleton root shared by every caller.
createPositionToElementA position relative to an element, updated from a reactive page position. Also returns the element's current bounds.

Common parameters:

ParamDesc
targetSVGSVGElement, HTMLElement, Window or Document.
touchListen to touch events. If on, the position updates on touchstart.
followTouchIf on, the position updates on touchmove.
initialValuesThe initial values.
posFor createPositionToElement: an accessor of the page position (relative to the page, not the window).
Bindings
[<Erase; AutoOpen>]
type Mouse =
    [<Import("makeMousePositionListener", path); ParamObject(2)>]
    static member makeMousePositionListener (target: U4<HtmlElement, Element, Document, Window>, callback: (MousePosition -> unit), ?touch: bool, ?followTouch: bool) : DisposeCallback = nativeOnly

    [<Import("makeMouseInsideListener", path); ParamObject(2)>]
    static member makeMouseInsideListener (target: U4<HtmlElement, Element, Document, Window>, callback: (bool -> unit), ?touch: bool) : DisposeCallback = nativeOnly

    [<Import("getPositionToElement", path)>]
    static member getPositionToElement(pageX: int, pageY: int, el: U4<HtmlElement, Element, Document, Window>): PositionRelativeToElement = nativeOnly

    [<Import("getPositionInElement", path)>]
    static member getPositionInElement(pageX: int, pageY: int, el: U4<HtmlElement, Element, Document, Window>): PositionRelativeToElement = nativeOnly

    [<Import("getPositionToScreen", path)>]
    static member getPositionToScreen(pageX: int, pageY: int): Position = nativeOnly

    [<Import("createMousePosition", path)>]
    static member createMousePosition (?target: U4<HtmlElement, Element, Document, Window>, ?initialValues: MousePositionInside, ?touch: bool, ?followTouch: bool) : MousePositionInside = nativeOnly

    [<Import("createMousePosition", path); ParamObject(1)>]
    static member createMousePosition (?target: U4<Accessor<HtmlElement>, Accessor<Element>, Accessor<Document>, Accessor<Window>>, ?initialValues: MousePositionInside, ?touch: bool, ?followTouch: bool) : MousePositionInside = nativeOnly

    [<Import("useMousePosition", path)>]
    static member inline useMousePosition: (unit -> MousePositionInside) = nativeOnly

    [<Import("createPositionToElement", path); ParamObject(2)>]
    static member createPositionToElement (element: U4<HtmlElement, Element, Accessor<HtmlElement>, Accessor<Element>>, pos: Accessor<Position>, ?initialValues: PositionRelativeToElement, ?touch: bool, ?followTouch: bool) : PositionRelativeToElement = nativeOnly
Edit this page