I know there is a way to delay calls with set timeout like here. But is there a way to only call the function if a certain amount of time passed?
Here is what I am trying to do: I am trying to block a section of the UI during an Ajax call, but if the call is quick (i.e. maybe less than half a second) I don’t want to block the UI as it results in that quick blip of a different screen before it goes away and is a little disruptive to a user.
Basically what I am looking for is if there is a way to delay the block UI call for a certain amount of time (say 1 second or something) and then ‘cancelling’ it if the Ajax call completes before the call happens. However, if the call does take more than that amount time the function call would still happen.
Is there a way to accomplish this? Or maybe there is a better way I am overlooking.
Source: Stack Jquery