1.0.3 • Published 4 years ago

mobile-touch-gesture v1.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

mobile-touch-gesture

current version 1.0.3

Foreword

This is a mobile touch gesture and pc mouse gesture library.

Feature

Gestures are supported below:

swiperStart, swiperMove, swiperEnd, swiperLeft,swiperRight, swiperUp, swiperDown,

swiperLeftRight, swiperLeftUp, swiperLeftDown,

swiperRightLeft, swiperRightUp, swiperRightDown,

swiperUpDown, swiperUpLeft, swiperUpRight,

swiperDownUp, swiperDownLeft ,swiperDownRight,

tap, doubleTap, longTap.

Usage

Import mobile touch gesture library, then new an instance via some necessary arguments.

import MobileTouchGesture from "mobile-touch-gesture";
......
const MTG = new MobileTouchGesture(document.documentElement || document.body, {
    // set tips text
    prompt: {
        nameMap: {
            swiperUp: 'Up!!!',
            swiperRight: 'Right!!!'
        }
    },
    // trigger function
    swiperStart(val) {
        console.log(val)
    },
    swiperMove(val1, val2) {
        console.log(val1, val2)
    },
    swiperEnd(val) {
        console.log(val)
    },
    swiperLeft() {
        console.log('swiperLeft')
    },
    swiperRight() {
        console.log('swiperRight')
    },
    swiperUp() {
        console.log('swiperUp')
    },
    swiperDown() {
        console.log('swiperDown')
    },
    swiperLeftRight() {
        console.log('swiperLeftRight')
    },
    swiperLeftTop() {
        console.log('swiperLeftTop')
    },
    swiperLeftDown() {
        console.log('swiperLeftDown')
    },
    swiperRightLeft() {
        console.log('swiperRightLeft')
    },
    swiperRightUp() {
        console.log('swiperRightUp')
    },
    swiperRightDown() {
        console.log('swiperRightDown')
    },
    swiperUpDown() {
        console.log('swiperUpDown')
    },
    swiperUpLeft() {
        console.log('swiperUpLeft')
    },
    swiperUpRight() {
        console.log('swiperUpRight')
    },
    swiperDownUp() {
        console.log('swiperDownUp')
    },
    swiperDownLeft() {
        console.log('swiperDownLeft')
    },
    swiperDownRight() {
        console.log('swiperDownRight')
    },
    tap(e) {
        console.log('tap')
    },
    doubleTap(e) {
        console.log('doubleTap')
    },
    longTap(e) {
        console.log('longTap')
    }
})

MobileTouchGesture class acept two arguments, first is target element, second is an options object

Arguement

attributetypedefalut valuedescrition
eleElementtarget element
optionsObjectoptions

Basice gestures: swiperStart, swiperMove, swiperLeft,swiperRight, swiperUp, swiperDown, swiperLeftRight, swiperRightLeft, swiperUpDown, swiperDownUp , tap, doubleTap, longTap.

If you want to handler more complex situation, you can use swiperStart and swiperMove to handle it.

You can get library version via MobileTouchGesture.version.

Options attributes

attributetypedefalut valuedescrition
effectiveValueNumber20trigger function until move distance reach effectiveValue
promptObject{show: false, nameMap:{invalid: 'invalidgesture'} }show attribute is to defined tips show or not, and you can use nameMap to redefined gesture tips, when gesture is triggered
longTapTimeNumber200 mslong press trigger time
doubleTapTimeNumber200 msdouble click gap time

You can redefine time for long tap and double tap to trigger relative event.

Options funtions

attributetypedefalut valuedescrition
swiperLeftFunctionfunction(){}slide left
swiperRightFunctionfunction(){}slide right
swiperUpFunctionfunction(){}slide up
swiperDownFunctionfunction(){}slide down
swiperLeftRightFunctionfunction(){}slide left then back
swiperLeftUpFunctionfunction(){}slide left then up
swiperLeftDownFunctionfunction(){}slide left then down
swiperRightLeftFunctionfunction(){}slide right then back
swiperRightUpFunctionfunction(){}slide right then up
swiperRightDownFunctionfunction(){}slide right then down
swiperUpDownFunctionfunction(){}slide up then back
swiperUpRightFunctionfunction(){}slide up then right
swiperUpLeftFunctionfunction(){}slide up then left
swiperDownUpFunctionfunction(){}slide down then back
swiperDownRightFunctionfunction(){}slide down then right
swiperDownLeftFunctionfunction(){}slide down then left
tapFunctionfunction(e){}click
doubleTapFunctionfunction(e){}double click
longTapFunctionfunction(e){}long press
swiperStartFunctionfunction(val){}trigger when touch start
swiperMoveFunctionfunction(val1, val2){}trigger when move start
swiperEndFunctionfunction(val1, val2){}trigger when move end

中文文档

http://yunkus.com/post/5ddb6b3cf9b59b20e611e714