Barry Tormey
Barry Tormey

Reputation: 3126

Allowing Only Single Touch jQuery Touchscreen

I'm working with an HP Touchscreen desktop computer, developing a simple website. I would like to prevent the user from "mashing" the screen clicking with eight fingers at one time. Is there a way in jQuery to allow only a single touch event to register at a time? So that when the first finger hits the screen, that is the one that is registered and all other touches are ignored until that finger reaches a touchend?

Upvotes: 0

Views: 1030

Answers (2)

Barry Tormey
Barry Tormey

Reputation: 3126

Ok, so here is the solution I used:

var isTouched = false;
var $document = $(document);

$document.on('touchstart', function () {
    if (!isTouched) {
        isTouched = true;
        $document.off('touchstart', function () {
            $document.on('touchend', function () {
                isTouched = false;
                $document.bind('touchstart');
            });
        });
     }
});

Upvotes: 0

maccettura
maccettura

Reputation: 10818

Disable the input type (button, textbox, etc) after it is clicked, enable it after your logic has been completed.

EDIT: If you are trying to disable all touch events until touchend has been fired try something like this:

var isProcessing = false;

$(document).on("touchstart",function(e){
    e.preventDefault();
    if(!isProcessing){
        isProcessing = true;
        //Do your stuff here
    }    
});

$(document).on("touchend",function(e){
    e.preventDefault();
    isProcessing = false; 
});

Upvotes: 2

Related Questions