Jest sobie taki skrypcik:
Kod
<sctipt type="text/javascript">
<!--
///////////////////////////////////////////////////////////////////////////////////////////////
// Script by Paul Proft, [url="http://proft.50megs.com/JSdemos.html"]http://proft.50megs.com/JSdemos.html[/url] //
//////////////////////////////////////////////////////////////////////////////////////////////
// Set timer lengths in HTML code for start buttons at bottom of this document.
// Set desired container width and interval duration here:
containerWidth = 254; // pixels (smaller widths draw smoother progress bars)
intervalDuration = 250; // milliseconds (depending on computer speed, smaller interval durations might yield inaccurate progress)
drawBar=0;
function progressBar(duration) {
resetStart(); // reset variables and style for button-click
ref=new Date(); start=ref.getTime(); // gets start time for accuracy check (optional)
increment = intervalDuration*containerWidth/duration; // container increment reference (pixels)
barWidth = interval*increment; // bar incremental width (pixels)
drawBar = setInterval('progress('+duration%intervalDuration+','+juz+')', intervalDuration); // updates progress bar each interval duration
}
function progress(lastms) {
document.getElementById('bar').style.width=barWidth; // updates bar width each iteration
//document.getElementById('showsecs').innerHTML=Math.floor(interval*intervalDuration/1000); // updates displayed seconds (optional)
interval++; // increments interval for next iteration
if(interval*increment > containerWidth) { // tests for last iteration
clearInterval(drawBar); // clears setInterval
end=new Date(); end=lastms+end.getTime(); // gets end time for accuracy check (optional)
setTimeout("document.getElementById('bar').style.width=containerWidth",lastms); // completes bar width and duration
//setTimeout("document.getElementById('showsecs').innerHTML="+(lastms+intervalDuration*(interval-1))/1000, lastms); // final time
setTimeout('window.location="index.php?metoda=9"', lastms); // bar duration accuracy check (optional)
}
else barWidth = interval*increment; // bar width incremented in pixels
}
function resetStart() { // resets variables and style for button-click
if(drawBar) clearInterval(drawBar); // clears setInterval if running
document.getElementById('bar').style.width = 0; // sets bar width to zero
//document.getElementById('showsecs').innerHTML = 0; // sets seconds to zero
interval = 1; // initializes interval
}
//-->
</sctipt>
<!--
///////////////////////////////////////////////////////////////////////////////////////////////
// Script by Paul Proft, [url="http://proft.50megs.com/JSdemos.html"]http://proft.50megs.com/JSdemos.html[/url] //
//////////////////////////////////////////////////////////////////////////////////////////////
// Set timer lengths in HTML code for start buttons at bottom of this document.
// Set desired container width and interval duration here:
containerWidth = 254; // pixels (smaller widths draw smoother progress bars)
intervalDuration = 250; // milliseconds (depending on computer speed, smaller interval durations might yield inaccurate progress)
drawBar=0;
function progressBar(duration) {
resetStart(); // reset variables and style for button-click
ref=new Date(); start=ref.getTime(); // gets start time for accuracy check (optional)
increment = intervalDuration*containerWidth/duration; // container increment reference (pixels)
barWidth = interval*increment; // bar incremental width (pixels)
drawBar = setInterval('progress('+duration%intervalDuration+','+juz+')', intervalDuration); // updates progress bar each interval duration
}
function progress(lastms) {
document.getElementById('bar').style.width=barWidth; // updates bar width each iteration
//document.getElementById('showsecs').innerHTML=Math.floor(interval*intervalDuration/1000); // updates displayed seconds (optional)
interval++; // increments interval for next iteration
if(interval*increment > containerWidth) { // tests for last iteration
clearInterval(drawBar); // clears setInterval
end=new Date(); end=lastms+end.getTime(); // gets end time for accuracy check (optional)
setTimeout("document.getElementById('bar').style.width=containerWidth",lastms); // completes bar width and duration
//setTimeout("document.getElementById('showsecs').innerHTML="+(lastms+intervalDuration*(interval-1))/1000, lastms); // final time
setTimeout('window.location="index.php?metoda=9"', lastms); // bar duration accuracy check (optional)
}
else barWidth = interval*increment; // bar width incremented in pixels
}
function resetStart() { // resets variables and style for button-click
if(drawBar) clearInterval(drawBar); // clears setInterval if running
document.getElementById('bar').style.width = 0; // sets bar width to zero
//document.getElementById('showsecs').innerHTML = 0; // sets seconds to zero
interval = 1; // initializes interval
}
//-->
</sctipt>
wywołuje się go poleceniem:
progressBar(ilosc milisekund do odliczenia)
Działa fajnie, bo z php wyciągam ile sekund zostało i on odlicza. Jednak potrzebuje zrobić tak żeby skrypt wiedział ile ogólnie będzie trwać operacja i ile już przeleciało tego timera.
Chodzi o to że jak odświeżę stronę to php poda mniejsza ilość sekund a on znowu od 0 do tej liczby odmierza.
A ma już pamiętać ile było i odliczać do końca.