如何在滑动时执行 If?

How to do an If on swipe?

我想做一个 if on swipe 然后做这个否则做其他事情但我似乎无法让它工作?

JS:

if ($("p").on("swipe") == true)
{
  alert("You swiped!");
}
else
{
  //Stuff
}

我认为你正在寻找这个:

$("p").on("swipe", function(){ 
    alert("You swiped!"); 
});

正确使用swipe事件。

$("selector").on("swipe",function(event){
    console.log(event.handled); //Check this 
})

Swipe Event

我创建了一个 touchdown 和 touchup 事件来检查 Y & X coordinates 并且如果它们在 touchend 上 == 那么它是一个点击,否则..滑动。

简码:

x = e.originalEvent.touches[0].pageX; //<-- In a function like function(e){}
//Same for y.
y = e.originalEvent.touches[0].pageY;
if (x == y)
{
  //Click
}
else
{
  //Swipe
}