elm-lang/mouse/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Mouse

This library lets you listen to global mouse events. This is useful for a couple tricky scenarios including:

  • Detecting a "click" outside the current component.
  • Supporting drag-and-drop interactions.

Mouse Position

type alias Position =
{ x : Int
, y : Int
}

The position of the mouse relative to the whole document. So if you are scrolled down a bunch, you are still getting a coordinate relative to the very top left corner of the whole document.

position : Decoder Position

The decoder used to extract a Position from a JavaScript mouse event.

Subscriptions

clicks : (Position -> msg) -> Sub msg

Subscribe to mouse clicks anywhere on screen.

moves : (Position -> msg) -> Sub msg

Subscribe to mouse moves anywhere on screen. It is best to unsubscribe if you do not need these events. Otherwise you will handle a bunch of events for no benefit.

downs : (Position -> msg) -> Sub msg

Get a position whenever the user presses the mouse button.

ups : (Position -> msg) -> Sub msg

Get a position whenever the user releases the mouse button.