GithubHelp home page GithubHelp logo

plumpmath / virtual-dom-hammerjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danielnaab/virtual-dom-hammerjs

0.0 0.0 0.0 17 KB

A virtual-dom hook that enables interop with hammer.js.

License: MIT License

JavaScript 95.03% HTML 4.97%

virtual-dom-hammerjs's Introduction

virtual-dom-hammerjs

A simple virtual-dom hook that wraps Hammer.js events to the virtual-dom. The general idea comes from react-hammerjs, but this implementation supports all events and the complete Hammer.js feature set with a declarative api.

Usage

The manager property may be used to configure the Hammer manager. These properties will be merged with the default ones.

In addition, the actual Hammer.js object is exposed as Hammer.OPTS, from which one may access constants.

var Hammer = require('virtual-dom-hammerjs')
var h = require('virtual-dom/h')


function render(count)  {
    return h('div', {
        hammer: new Hammer({
            events: {
                tripletap: handleEvent,

                pan: handleEvent,
                panstart: handleEvent,
                panmove: handleEvent,
                panend: handleEvent,
                pancancel: handleEvent,
                panleft: handleEvent,
                panright: handleEvent,
                panup: handleEvent,
                pandown: handleEvent,
                pinch: handleEvent,
                pinchstart: handleEvent,
                pinchmove: handleEvent,
                pinchend: handleEvent,
                pinchcancel: handleEvent,
                pinchin: handleEvent,
                pinchout: handleEvent,
                press: handleEvent,
                pressup: handleEvent,
                rotate: handleEvent,
                rotatestart: handleEvent,
                rotatemove: handleEvent,
                rotateend: handleEvent,
                rotatecancel: handleEvent,
                swipe: handleEvent,
                swipeleft: handleEvent,
                swiperight: handleEvent,
                swipeup: handleEvent,
                swipedown: handleEvent,
                tap: handleEvent
            },
            manager: {
                touchAction: 'compute',
                recognizers: {
                    // Custom recognizers:
                    tripletap: {
                        type: 'Tap',
                        options: {
                            taps: 3
                        },
                        recognizeWith: ['tap']
                    },
                    panh: {
                        type: 'Pan',
                        options: {
                            direction: Hammer.OPTS.DIRECTION_HORIZONTAL
                        }
                    },
                    panv: {
                        type: 'Pan',
                        options: {
                            direction: Hammer.OPTS.DIRECTION_VERTICAL
                        },
                        requireFailure: ['panh']
                    },

                    // The following recognizers update the default ones:
                    pan: {
                        options: {
                            enable: true
                        }
                    },
                    pinch: {
                        options: {
                            enable: true
                        },
                        recognizeWith: ['rotate']
                    },
                    rotate: {
                        options: {
                            enable: true
                        }
                    },
                    swipe: {
                        options: {
                            enable: true,
                            pointers: 1,
                            threshold: 10,
                            direction: Hammer.OPTS.DIRECTION_ALL,
                            velocity: 0.65
                        },
                        recognizeWith: ['pan']
                    },
                    tap: {
                        options: {
                            enable: false,
                            time: 600,
                            threshold: 100
                        }
                    }
                }
            }
        })
    }, 'Touch Me')
}

virtual-dom-hammerjs's People

Contributors

danielnaab 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.