如何使用jQuery捕获滑动类型?

时间:2016-07-12 23:58:18

标签: javascript jquery jquery-mobile

我在jQuery中有这些代码行,我需要在字符串中捕获swype类型的名称。

$('.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

        }

1 个答案:

答案 0 :(得分:0)

如果我理解正确,你想要的是知道滑动是左还是右......

$('.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
   })
}