Code Monkey home page Code Monkey logo

better-gesture's Introduction

better-gesture

minzip version last commit issues

English | 中文 | Demo | Link

A gesture library use for pc, mobile, vue, and mini programs

  • Support multiple terminals: PC, Mobile, Vue, applet
  • Very small file size, no need to install any dependencies, the compressed code is only3.77KB
  • Good documentation support
  • Simple API design
  • Excellent performance
  • Rich gesture events:doubleTap longTap pressMove rotate pinch swipe ...
  • Support dynamic destruction, create gesture event

Install

NPM

npm install better-gesture

CDN

Able to pass unpkg.com/get the latest version of resources,introduce the js file on the page to start using it.

<!-- latest version of -->
<script src='https://unpkg.com/better-gesture/lib/better-gesture.umd.min.js'></script>

<!-- specify version -->
<script src='https://unpkg.com/[email protected]/lib/better-gesture.umd.min.js'></script>

Use

use in script

<script src='https://unpkg.com/better-gesture/lib/better-gesture.umd.min.js'></script>
<div id="example"></div>

<script>
  new BetterGesture(document.getElementById('example'), {
      pressMove(evt) {
          console.log(evt.deltaX, evt.deltaY)
      },
      rotate(evt) {
          console.log(evt.angle)
      },
      pinch(evt) {
          console.log(evt.zoom)
      },
      swipe(evt) {
          console.log(evt.direction)
      }
      //......
  })
</script>

use in vue

import Vue from 'vue'
import gesture from 'better-gesture'

Vue.use(gesture)
<template>
  <section class="example">
    <div v-gesture:pressMove="pressMove" v-gesture:doubleTap="doubleTap"> </div>
  </section>
</template>

<script>
export default {
  methods: {
      pressMove(evt) {
          console.log(evt.deltaX, evt.deltaY)
      },
      rotate(evt) {
          console.log(evt.angle)
      },
      pinch(evt) {
          console.log(evt.zoom)
      },
      swipe(evt) {
          console.log(evt.direction)
      }
      //......
  }
}
</script>

use in mini programs

npm build introduction

Execute the command to install the NPM package in the directory where the small package.json program is located

npm install better-gesture

Click on the Developer Tools menu bar: Tools -- Build NPM

Or a CDN download is introduced

click to download

// npm build introduction
import BetterGesture from './../miniprogram_npm/better-gesture/better-gesture.umd.min.js'

// cdn download and introduction
import BetterGesture from './../utils/better-gesture.js'

Use

It is recommended to use catch to capture the event, otherwise it will easily cause the monitoring animation to freeze

<!-- wxml -->
<!-- Must initialize event touchstart,touchmove,touchend,touchcancel-->
<!-- The function name must be defined as start,move,end,cancel -->

<view class='container'>
    <view
      catch:touchstart="start"
      catch:touchmove="move"
      catch:touchend="end"
      catch:touchcancel="cancel">
    </view>
</view>
import BetterGesture from './../utils/better-gesture.js'
Page({
    onLoad() {
        new BetterGesture(this, {
            pressMove(evt) {
                console.log(evt.deltaX, evt.deltaY)
            },
            rotate(evt) {
                console.log(evt.angle)
            },
            pinch(evt) {
                console.log(evt.zoom)
            },
            swipe(evt) {
                console.log(evt.direction)
            }
            //......
        })
    }
})

Mini programs code snippets: Click to view

More usage: https://wensiyuanseven.github.io/better-gesture

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.