how to trigger swipe event on click in hammerjs?

  hammer.js, javascript, jquery, swipe

I have a slider built with Hammer JS swipe events which is working fine. but when I tried to slide on click its not working as expected and only slides 1 time.

working code on swipe:

$(function () {
        $('div').each(function () {
            var $this = $(this);
            var h = new Hammer(this);
            h.get('swipe').set({ direction: Hammer.DIRECTION_ALL,velocity:0.3 });  

            h.on("swipeup", async function (e) {
                SlidePage($this,"down",definedLocations);
            });
            h.on("swipedown", async function (e) {
                SlidePage($this,"up",definedLocations);
            });

            h.on("swipeleft", async function (e) {
                SlidePage($this,"left",definedLocations);
            });
            h.on("swiperight", async function (e) {
                SlidePage($this,"right",definedLocations);
            });    
        });
    });

But When I tried to slide on click event it is working only 1 time.

function moveSlides(dir){            // dir is the direction passed on click event. 
        SlidePage($('div'), dir, definedLocations);    
}

P.S: is there any way to trigger Hammerjs Swipe events on click?

Source: Ask Javascript Questions

LEAVE A COMMENT