Grow your CSS skills. Land your dream job.

Last updated on:

Window load event with minimum delay

window.load can fire super duper fast if the page is cached. If you want to use that event but make sure a minimum amount of time has passed until it does...

(function fn() {

  fn.now = +new Date;

  $(window).load(function() {

     if (+new Date - fn.now < 500) setTimeout(fn, 500);
     
		 // Do something

  });

})();

Comments

  1. This is faster!

Leave a Comment

Current day month ye@r *

*May or may not contain any actual "CSS" or "Tricks".