Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

temporarily disable all events in javascript

How do you temporarily disable all events in javascript? We want to make them disabled, so that some events don't run until after 700 miliseconds after we click something.

like image 580
user1820022 Avatar asked Jan 17 '13 05:01

user1820022


2 Answers

If you're trying to temporarily disable all clicks, then a simple way to do that without changing any of the rest of your page or code is to put up a transparent div absolutely positioned over the whole page that intercepts and stops propagation of all click events. Then, use a setTimeout() to remove that transparent div at whatever time interval you want.

Put the blockDiv in your page HTML so it's already there.

In your HMTL:

<body>
    <div id="blockDiv"></div>
    ... other page HTML here
</body>

Then, have this CSS in the page:

#blockDiv {
    position: absolute;
    left: 0;
    right: 0;
    height: 100%;
    width: 100%;
    z-index: 999;
}

And, this javacript:

$("#blockDiv").click(function(e) {
    // stop propagation and prevent default by returning false
    return false;
});

setTimeout(function() {
    $("#blockDiv").remove();
}, 700);
like image 167
jfriend00 Avatar answered Sep 27 '22 00:09

jfriend00


setTimeout is what you want.

The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.

it takes two parameters:
1) the function or code to call and
2) the number of milliseconds to wait before executing the code/function.

 setTimeout(function(){
    //do your stuff
 },700);
like image 29
bipen Avatar answered Sep 27 '22 00:09

bipen