Code Monkey home page Code Monkey logo

lc-swiper's Introduction

TouchSwipe events made easy, by LCweb

No dependencies vanilla javascript class to easily handle swipe events on page elements.

  • gives you the swipe delta in each direction
  • supports multiple instances per element
  • features a destroy public method (targeting the specific instance)

What do you want more from 2KB of code? :P
NB: obviously it works only for touch devices.

Installation & Usage

  1. include lc-swiper.min.js

  2. initialize plugin targeting one/multiple page elements and the callback function triggered after each swipe.

    NB: first parameter may be a textual selector or a DOM object (yes, also jQuery objects)

You must use a valid callback function as second parameter. It will be triggered each time a swipe event is performed.
It has got two parameters:

<script type="text/javascript>
new lc_swiper('#swipe_target', function(directions, $el) {

    // .. do something awesome!

    /*
     * directions object composition:
     * {
        up      : (int) number of pixels swiped
        right   : (int) number of pixels swiped
        down    : (int) number of pixels swiped
        left    : (int) number of pixels swiped
     * }
     */

});
</script>

Multiple actions and the destroy method

As said, you can setup multiple instances of the class and also destroy the single instance for a granular control on what is enabled

<script type="text/javascript>
const instance1 = new lc_swiper('#swipe_target', function(dir, $el) {
    ... 
});

const instance2 = new lc_swiper('#swipe_target', function(dir, $el) {
    ... 
});


// stop performing the first instance callback on swipe
instance1.destroy();
</script>

Copyright © Luca Montanari - LCweb

lc-swiper's People

Contributors

lcweb-ita 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.