G. Recchia G. Recchia - 4 months ago 14
Javascript Question

How do I catch the swipe type with jQuery?

I have these lines of code in jQuery and I need to catch the name of the swype type in a string.

$('.client-content').on('swipeleft swiperight', function(){

var curActiveClient = $('.clients-belt').find('.active-client'),
position = $('.clients-belt').children().index(curActiveClient),
clientNum = $('.client-unit').length;

if (event === 'swipeleft') {

//do something

} else if (event === 'swiperight') {

//do something else

}

Answer

If I'm understanding correctly, what you want is to know whether the swipe is left or right...

$('.client-content').on('swipe', function(){
   var curActiveClient = $('.clients-belt').find('.active-client'),
      position = $('.clients-belt').children().index(curActiveClient),
      clientNum = $('.client-unit').length;

   $(this).on("swipeleft", function(){
   //some code
   })
   $(this).on("swiperight", function(){
   //some code
   })
}
Comments