Saturday, 15 August 2015

html - jquery setTimeout or setInterval -



html - jquery setTimeout or setInterval -

i have below code if condition

if(oldmembership++ <= newmembership) { var digit; $('ul#indexsitecounterbottom').empty(); for(i = 0; < 9; i++) { if(membership.tostring()[i] == '_') { digit = '&nbsp;'; } else { digit = membership.tostring()[i]; } $('ul#indexsitecounterbottom').append('<li>'+digit+'</li>'); $('ul#indexsitecounterbottom li:nth-child(3n)').addclass('extra-margin'); } }

if 'if' status meet rest of code run.

i want able slow running of below code around 500ms each loop of 'if'.

i've tried set in setinterval , settimeout haven't used them before , 'if' status completed loops instantly.

how can add together setinterval or settimeout each 'if' loop delayed 500ms? 1 time 'if' status meet should drop out of timer/if condition.

thankyou much...

i think can resolve problem...

function execute_if_membership(){ settimeout(function(){ var digit; $('ul#indexsitecounterbottom').empty(); for(i = 0; < 9; i++) { if(membership.tostring()[i] == '_') { digit = '&nbsp;'; } else { digit = membership.tostring()[i]; } $('ul#indexsitecounterbottom').append('<li>'+digit+'</li>'); $('ul#indexsitecounterbottom li:nth-child(3n)').addclass('extra-margin'); } // execute 1 time again if needed if(oldmembership++ <= newmembership) {execute_if_membership();} else{ /* else? maybe phone call function */ } },500); } // execute first time if(oldmembership++ <= newmembership) {execute_if_membership();}

 

edit: code phone call function first time. function wait 500 ms , execute, in final of function, checks if need phone call time (loop) , if needed executes again. if want execute code after that, need set within else of condition, because if set code below, executed without wait. that's because settimeout , setinterval makes code asynchronous , continues execute code.

jquery html css

No comments:

Post a Comment