Posted By

inamorix on 05/09/08


Tagged

js


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

nbsp
sidonaldson
sepidol
alexteg


document.ready


 / Published in: JavaScript
 

  1. (function () {
  2. var ie = !!(window.attachEvent && !window.opera);
  3. var wk = /webkit\/(\d+)/i.test(navigator.userAgent) && (RegExp.$1 < 525);
  4. var fn = [];
  5. var run = function () { for (var i = 0; i < fn.length; i++) fn[i](); };
  6. var d = document;
  7. d.ready = function (f) {
  8. if (!ie && !wk && d.addEventListener)
  9. return d.addEventListener('DOMContentLoaded', f, false);
  10. if (fn.push(f) > 1) return;
  11. if (ie)
  12. (function () {
  13. try { d.documentElement.doScroll('left'); run(); }
  14. catch (err) { setTimeout(arguments.callee, 0); }
  15. })();
  16. else if (wk)
  17. var t = setInterval(function () {
  18. if (/^(loaded|complete)$/.test(d.readyState))
  19. clearInterval(t), run();
  20. }, 0);
  21. };
  22. })();

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: thinhtu on October 13, 2010

how using it ?

Posted By: inamorix on February 25, 2011

document.ready(function () { // do anything... });

Posted By: ramonlechuga on March 12, 2011

why do you need to do the scroll ?

You need to login to post a comment.