javascript - How long does the jquery .ready() function wait? -
javascript - How long does the jquery .ready() function wait? -
i have page on php output rather big div, has lots of components within it. js handle div begins instantaneously, there problems of timing related loading of bigdiv , script handles it.
so, applied code handle on ready()
var bigdiv = $(document).find('#bigdiv'); bigdiv.ready(function{ //some code here });
now question is, if bigdiv
takes long time appear, how long ready()
function wait? if bigdiv
not appear @ all?
so avoid script waiting it, applied timeout,
thus chose approach this:
var waittimer = 0; var lodtmout = 2000; function chkdatalod(){ var bigdiv = $ph(document).find('#bigdiv'); if(bigdiv.length > 0){//find if bigdiv has content bigdiv.ready(function(){//wait bigdiv load it's contents //some code here }); }else{ //chk bigdiv after every 500 msec 2000 msec if(waittimer === lodtmout){ homecoming false; }else{ waittimer += 500; settimeout('chkdatalod();',500); } } }; function _init(){ chkdatalod(); } _init();
initially tried see if bigdiv's content length more zero. problem occured when 'incompletely loaded' bigdiv beingness displayed. 1 time again added .ready()
function. have animation functions on bigdiv don't want initiate until loaded.
this bigdiv
loaded cdn load timings varying. 1 day took 5 seconds load. seeing own approach know has problems. using settimeout , ready, both. unsure of how ling ready waits. tried see it's documentation couldn't find clearly.
how can solve specified situation??
the easiest way run code after closing tag of element. this
<div id='bigdiv>....</div> <script> // whatever want div </script>
ps: or may seek access element after div interval. if exists - div ready.
javascript jquery dom
Comments
Post a Comment