Giter Site home page Giter Site logo

elm-mouse-events's Introduction

elm-mouse-events

WARNING: This package will be merged into elm-pointer-events when the release 0.19 of elm will be out. It won't be updated to elm 0.19.

This package aims at handling mouse events in elm with more details than in Html.Events.

Motivation

When dealing with mouse events, I often need to access mouse coordinates. Functions onMouseDown and others from elm Html.Events module do not provide the coordinates of the mouse event.

Thanks to the use of the on function from Html.Events and some custom json decoders, this package provides mouse events with coordinates.

Usage

A functional example is available in the examples/ folder. But to have an overview of how to use this package, see below what a Msg type and an Attribute Msg might look like using this Mouse module:

import Mouse

type Msg
    = MouseDown Mouse.Event
    | MouseMove Mouse.Event
    | MouseUp Mouse.Event

mouseEvents : List (Html.Attribute Msg)
mouseEvents =
    [ Mouse.onDown MouseDown
    , Mouse.onMove MouseMove
    , Mouse.onUp MouseUp
    ]

The Mouse.Event type

The Mouse.Event type is a reflection of the JavaScript specification of a mouse event. The attributes kept are:

Go see it's definition in the Mouse module to know its exact record structure.

Documentation

The package documentation is available on the elm package website.

License

This Source Code Form is subject to the terms of the Mozilla Public License,v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

Authors

Original author: Matthieu Pizenberg ([email protected])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.