0

I am trying to create a swipe effect with help of hammer.js but it seems it creating a issue with jquery file

jquery code with hammer

       $( document ).ready(function() {
    console.log( "ready!" );

        $(".swiper").hammer().on("swipeleft", function(event) {
    //callback

     console.log( "swipeleft!" );

});
});

html code

error

enter image description here

Kundan SIngh
  • 720
  • 2
  • 12
  • 34

1 Answers1

0

I am assuming you have already included hammer.js and jQuery in your project. You can try this now.

var hammer = new Hammer($(".swiper")[0]);
hammer.on("swipeLeft", function(evt){
console.log("Swipe Left");
});
Nitesh
  • 1,490
  • 1
  • 12
  • 20
  • i am not getting the console.log("Swipe Left"); – Kundan SIngh Dec 26 '16 at 15:00
  • https://jsfiddle.net/pmpmvwry/1/ hammer will not work in jsfiddle as it is without https – Kundan SIngh Dec 27 '16 at 06:43
  • You can check this. Try swiping on first 'li' element. It works fine. https://jsfiddle.net/pmpmvwry/2/ – Nitesh Dec 27 '16 at 08:21
  • but its does not work for all, As you have added a array number, how to make it to work all – Kundan SIngh Dec 27 '16 at 10:47
  • You need to pass a JS DOM element to hammer constructor (not jQuery object). That's why I am passing first 'li' element. If you want to apply swipe on all 'li' elements, better use 'ul' element instead of 'li'. For more info, check this http://hammerjs.github.io/getting-started/ – Nitesh Dec 27 '16 at 12:49