Code Monkey home page Code Monkey logo

elm-pointer-events's Introduction

elm-pointer-events

This package aims at handling pointer events in elm. Pointer events are a unified interface for similar input devices (mouse, pen, touch, ...).

Since maintaining both mouse and touch events for compatibility is really cumbersome, using a unified pointer events interface is a relief. However this API is not well supported by all browsers. So I strongly recommend to use it in pair with the elm-pep polyfill for compatibility with all major browsers.

Usage

The following functions can easilly be used to generate attribute messages:

Pointer.onDown : (Pointer.Event -> msg) -> Html.Attribute msg
Pointer.onMove : (Pointer.Event -> msg) -> Html.Attribute msg
Pointer.onUp : (Pointer.Event -> msg) -> Html.Attribute msg

If you are using the elm-pep polyfill for compatibility with Firefox and Safari, you have to add the elm-pep attribute. It is also recommended that you deactivate touch-action to disable browsers scroll behaviors.

div
    [ Pointer.onDown ...
    , Pointer.onMove ...
    , Pointer.onUp ...
    -- no touch-action
    , Html.Attributes.style [ ( "touch-action", "none" ) ]
    -- Add this to your list of attribute messages
    , Html.Attributes.attribute "elm-pep" "true"
    ]
    []

Example

An example is available in the examples/ directory. To test it, compile the elm file with the command:

elm-make PointerEvents.elm --output PointerEvents.js

Then use any static http server like:

python3 -m http.server 8888

And open your browser at localhost:8888 to load the index.html page.

Want to contribute?

If you are interested in contributing in any way (feedback, bug report, implementation of new functionality, ...) don't hesitate to reach out on slack (user mattpiz) and/or open an issue.

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

Matthieu Pizenberg: [email protected]

elm-pointer-events's People

Contributors

mpizenberg avatar

Watchers

 avatar  avatar

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.