moubik Posted October 21, 2007 Report Posted October 21, 2007 vreau sa fac un sleep in javascript dar fara sa-mi duca procesorul la 100%ca in exemplul:function pause(millis) { var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date < millis)} si nici metoda asta nu ma ajuta, pentru ca nu stiu de cate ori se va parcurge loop-ul:setTimeout('nextpieceofcode();', 5000);pe net nu am gasit rezolvari diferite de cele 2 Quote
vladiii Posted October 23, 2007 Report Posted October 23, 2007 Ce am gasit aici: http://forums.codewalkers.com/client-side-things-82/javascript-sleep-82584.html ,dar nu am testat:function pause(numberMillis) {var now = new Date();var exitTime = now.getTime() + numberMillis;while (true) {now = new Date();if (now.getTime() > exitTime)return;}}Pe de alta parte, ai putea sa incerci VBScript:<script language='vbscript'>WScript.Sleep(1000)</script>Bafta !!! Quote
moubik Posted October 26, 2007 Author Report Posted October 26, 2007 ms vladiiinu stiam exact cum sa integrez vbscriptul asa ca pana la urma am gasit o solutie.de exemplu am functia//puneti orice valoare aici ca sa nu dea eroare cand face primul clearTuneOut//sincer nu stiu ce se poate intampla daca faci unset la o variabila care ar putea fi importanta var rec = 1function recursiva(){ //yeah, i'm a programmer //codul vine aici //si ca sa fac delay pot sa fac asa //golesc variabila de timeout clearTimeout(rec); //pui aici conditia de stop if (amterminat != true) { rec = setTimeOut("recursiva()", 500); }} Quote
moubik Posted October 27, 2007 Author Report Posted October 27, 2007 ok, am reusit sa fac ce doream dar am dat de alta problema si nu inteleg de ce se intampla asa.am codul:<head><script>theshit = "Ma enerveaza ca nu merge pe Firefox. Stie cineva de ce ?";doingshit = 5;bucket = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890!<>'();/=+-*";bucket = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890!.|_?";//bucket = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";function start(){ //create junk, var whereto = document.getElementById('text'); var tempax = ""; for (i=0 ; i<theshit.length ; i++) { tempax = tempax + bucket.charAt(Math.floor (Math.random() * (bucket.length))); } whereto.innerHTML = tempax; startToDoShit();}function startToDoShit(){ var whereto = document.getElementById('text'); var tempax = ""; var there = whereto.innerHTML; var modificari = 0; for (i=0 ; i<theshit.length ; i++) { if (there.charAt(i) != theshit.charAt(i)) { tempax = tempax + bucket.charAt(Math.floor (Math.random() * (bucket.length))); modificari = 1; } else { tempax = tempax + theshit.charAt(i); } } whereto.innerHTML = tempax; tempax = ""; clearTimeout(doingshit); if (modificari == 1) doingshit = setTimeout("startToDoShit()", 10);}function scrapheap(){document.getElementById('text').innerHTML=String.fromCharCode(Math.floor (Math.random() * (255)));}//</script></head><body onload="start()"><font face="courier"><div id="text">nu ar trebui sa existe</div></font></body>faza este ca merge pe opera si pe internet explorer, dar pe firefox nu merge.daca este sa scot liniile <font face="courier"> si </font> merge si pe firefox, dar nu arata asa cum doresc eu stie cineva de ce? Quote
konkhra Posted October 27, 2007 Report Posted October 27, 2007 <head><script>theshit = "Acum ar trebui sa mearga si pe Firefox. Spune-mi daca-ti merge. KONKHRA";doingshit = 5;bucket = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890!<>'();/=+-*";bucket = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890!.|_?";//bucket = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";function start(){ //create junk, var whereto = document.getElementById('text'); var tempax = ""; for (i=0 ; i<theshit.length ; i++) { tempax = tempax + bucket.charAt(Math.floor (Math.random() * (bucket.length))); } whereto.innerHTML = tempax; startToDoShit();}function startToDoShit(){ var whereto = document.getElementById('text'); var tempax = ""; var there = whereto.innerHTML; var modificari = 0; for (i=0 ; i<theshit.length ; i++) { if (there.charAt(i) != theshit.charAt(i)) { tempax = tempax + bucket.charAt(Math.floor (Math.random() * (bucket.length))); modificari = 1; } else { tempax = tempax + theshit.charAt(i); } } whereto.innerHTML = tempax; tempax = ""; clearTimeout(doingshit); if (modificari == 1) doingshit = setTimeout("startToDoShit()", 10);}function scrapheap(){document.getElementById('text').innerHTML=String.fromCharCode(Math.floor (Math.random() * (255)));}//</script><style type="text/css"><!--.style1 {font-family: "Courier New", Courier, monospace}--></style></head><body onLoad="start()"><div class="style1" id="text">nu ar trebui sa existe</div></body> Spune-mi daca-ti merge. Good luck! Quote
moubik Posted October 27, 2007 Author Report Posted October 27, 2007 merge, merci. problema inainte aparea de la faptul ca nu reusea sa faca verificarea corect.nu inteleg de ce totusi.. Quote
konkhra Posted October 27, 2007 Report Posted October 27, 2007 Cu placere. Da, depinde de la browser la browser. Probabil cu firebug ai putea vedea exact unde este problema. Nu prea ma pricep sa umblu cu el. Quote