Skip to content

Instantly share code, notes, and snippets.

@Anye
Created October 13, 2017 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anye/377aa90ce2e0cdd8225c27f0b5042bdc to your computer and use it in GitHub Desktop.
Save Anye/377aa90ce2e0cdd8225c27f0b5042bdc to your computer and use it in GitHub Desktop.
Pure javascript implement for jQuery's .ready(), usage: document.ready(function() { /*you code*/ });
(function () {
var ie =!!(window.attachEvent&&!window.opera),wk=/webkit\/(\d+)/i.test(navigator.userAgent)&&(RegExp.$1<525);
var fn =[],run=function(){for(var i=0;i<fn.length;i++)fn[i]();},d=document;d.ready=function(f){
if(!ie&&!wk&&d.addEventListener){return d.addEventListener('DOMContentLoaded',f,false);}if(fn.push(f)>1)return;
if(ie)(function(){try{d.documentElement.doScroll('left');run();}catch(err){setTimeout(arguments.callee,0);}})();
else if(wk)var t=setInterval(function(){if(/^(loaded|complete)$/.test(d.readyState))clearInterval(t),run();},0);};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment