This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.0.1
Track dragging motions when the mouse is down
version 2.0.0
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 2.0.0
Committed At 2017-02-01 14:41:21 UTC
elm-lang/mouse 1.0.1 <= v < 2.0.0 1.0.1
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1

Modules

README

elm-drag

This module listens for mouse events and creates drag events that contain the delta x and y of the mouse's movement when the button is pressed down.

Here's an example of an application that tallies the total distance the mouse has been dragged:

See an example here: https://runelm.io/c/48m

module Main exposing (..)

import Html
import Html exposing (Html, text)
import Drag


type alias Model =
    { dragModel : Drag.Model
    , dragDistance : Int
    }


type Msg
    = DragMsg Drag.Msg
    | Drag ( Int, Int )


init : ( Model, Cmd Msg )
init =
    let
        initialModel =
            { dragModel = Drag.initialModel
            , dragDistance = 0
            }
    in
        ( initialModel, Cmd.none )


subscriptions : Model -> Sub Msg
subscriptions model =
    Sub.map DragMsg <| Drag.subscriptions model.dragModel


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        DragMsg msg ->
            let
                ( newDragModel, dragCmd ) =
                    Drag.update Drag msg model.dragModel
            in
                ( { model | dragModel = newDragModel }, dragCmd )

        Drag ( dx, dy ) ->
            ( { model | dragDistance = model.dragDistance + (abs dx) + (abs dy) }, Cmd.none )


view : Model -> Html Msg
view model =
    text <| toString model


main =
    Html.program
        { init = init
        , update = update
        , subscriptions = subscriptions
        , view = view
        }