2015-10-06 205 views
0

我使用这个link的jQuery函数来识别'向下滑动'和'向上滑动'事件。jquery - 识别向上滑动和向下滑动

该功能工作正常,如果我只是使用swipedown或然而,我无法找到如何识别两个方向内的一个功能。例如:

$("body").on("swipeupdown",function(){ 

    if (swipeUp == true) { 

    alert("SwipedUp"); 
    } 

if (swipeDown == true) { 

    alert("SwipedDown"); 
    } 

}); 

任何想法如何实现?

我也尝试了下面的代码工作,但是,它统计了滑动,并显示了很多警报窗口超时我刷卡。

$(function(){ 
// Bind the swipeHandler callback function to the swipe event 
    $("body").on("swipe", swipeHandler); 

    // Callback function references the event target and adds the 'swipe' class to it 
    function swipeHandler(event){ 
     console.log(event); 
    } 
}); 

工作实例:

$("body").on("swipeupdown",function(){ 


    $("body").on("swipedown",function(){ 

    alert("down"); 

    }); 

    $("body").on("swipeup",function(){ 

    alert("up"); 

    }); 


}); 
+0

建议查看JQuery Mobile框架。这增加了滑动的虚拟事件。 – Twisty

+0

另外,swipeUp和swipeDown定义在哪里? – Twisty

+0

嗨Twisty,他们没有定义它只是我试图实现的一个例子。请参阅我的编辑 – SNos

回答