I'm building something mainly for use on tablets, where the user can tap an item on the screen and a class is applied to it. This is what I have so far:
The problems:
- I want to use touch events to remove the class and add the class on touch end (to make it faster).
- I don't want it to do anything if the user swipes (touchmoves).
I've tried a number of things, none of which have worked. The simplest I've tried (unsuccessfully) is this:
var dragging = false;
$(".items").on("touchmove", function(){
dragging = true;
});
$('.items').on("click touchend", function(event){
if (dragging = true){
}
else{
$('.items').removeClass('selected');
$(this).addClass('selected');
}
});
if (dragging = true)
should just beif (dragging)
, or better yetif (!dragging)
then move everything in the else statement into the if statement (therefore, you will have no else). – Indistinctivetouchmove
once, you are settingdragging = true
, this will a not allow any other clicks as per your code. You must resetdragging = false
after the event finishes. – Lutes