Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * timedInterval
- *
- * The method calls a function or evaluates an expression at specified intervals (in milliseconds)
- * until a specified number of milliseconds.
- *
- * @param {Function} callback
- * @param {int} interval - run every [interval] ms
- * @param {int} expiration - run until [expiration] in ms
- * @param {mixed} callbackArgs - arguments for callback function
- * @return {function}
- */
- function timedInterval(callback, interval, expiration, callbackArgs = null) {
- var wait = false;
- return function() {
- if (wait) {
- return;
- }
- wait = true;
- var handle = setInterval(function() {
- callback.call();
- }, interval);
- setTimeout(function() {
- clearInterval(handle);
- wait = false;
- }, expiration);
- };
- };
- // Example:
- var onScroll = timedInterval(function(){
- // code
- }, 500, 10000, null);
- $( window ).on( "scroll", onScroll );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement