2

I want the call function to run every 1.5 seconds. However, if you are clicking continuously on a mobile machine From the moment the call function is called in succession.

This is the code I am using:

$('#sendVideo').unbind('click');
$('#sendVideo').bind('click', function (event) {
    $("#sendVideo").prop("disabled", true);
    call();
    setTimeout("$('#sendVideo').prop('disabled', false);", 1500);
});

Is there a solution for this?

2 Answers 2

3

You can use a clever hack:

var clickInProgress = false;
$('#sendVideo').bind('click', function (event) {
    if(clickInProgress) return;
    clickInProgress = true;
    $("#sendVideo").prop("disabled", true);
    call();
    setTimeout("$('#sendVideo').prop('disabled', false); clickInProgress=false;", 1500);
});
Sign up to request clarification or add additional context in comments.

2 Comments

it's can be nice idea to use disabled prop as this status
The value of clickInProgress does not change in setTimeout ("$ ('# sendVideo'). Prop ('disabled', false);
0

You can set a flag on the element during the capture phase and delete it during bubble phase. I am not sure about jQuery but in simple java-script you can achieve it like this:

// set the flag on at capture
document.querySelector("#sendVideo").addEventListener('click', function(e) {
    if (this.flagOn) {
        e.preventDefault();
        return false;
    }
    this.flagOn = true;
    return true;
}, true);
// delete on bubble
document.querySelector("#sendVideo").addEventListener('click', function(e) {
    delete this.flagOn;
}, false);

This should handle that for you without any modification in your own code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.