This is often called “polling”, and I’ve created a handy JS function that you can use for all of your polling needs. Here is the polling variable function:
This variable takes a function and applies another function and polling timer based on parameters set. I use this most commonly with the
window.resize event, so here is an example of how you would use this (I’m using jQuery here):
Here we poll the
window.resize event every 25ms and fire our anonymous function that is passed into the poll variable. We can check for flags and other things before doing anything if necessary.
This function always comes in handy, so I hope you can make use of it too!