Joined: 19 Jun 2004 Posts: 42 Location: Zagreb, Hrvatska
Posted: 15.04.2005 08:26 Post subject: Real time counter!?
Evo ovako, odite na Deviantart, vidite ovaj brojač koji imaju koji broji pristigle radove, radi u realnom vremenu, bez refresha. Kako to izvesti, malo sam im gledao source code, mislim da koriste neki javascript, evo ga:
Code:
//<![CDATA[
try{
var Deviations=11557203,DevCount,DevTimes=("1 0 1 1 0 6 0 1 5 0 3 4 0 0 2 8 3 0 2 3 2 1 1 1 1 1 3 0 2 0 7 0 0 5 3").split(" "),iDev=0;
DevCount=document.getElementById("devlove");
function Deviate(){
var r;
DevCount.childNodes[0].nodeValue = prettyNumber(Deviations++)+" deviations";
r=DevTimes[iDev++];
if(iDev==DevTimes.length)iDev=0;
r*=1000;
r+=Math.random()*100+(r?-50:Math.random()*500); // Fluctuate, since given times are rounded
window.setTimeout("Deviate();",r);
}
Deviate();
}catch(e){}
//]]>
Neznam jeli ovo stvarno javascript, može li mi netko malo pojasniti kod, htio bih nešto slično izvesti na mom siteu.
Joined: 19 Jun 2004 Posts: 42 Location: Zagreb, Hrvatska
Posted: 24.04.2005 08:04 Post subject:
Evo, ovo se includa na mjesto gdje treba biti brojac:
Code:
<!--
quota = el("quota");
updateQuota();
// -->
a ovo su funkcije:
Code:
function updateQuota() {
if (!quota) {
return;
}
var now = (new Date()).getTime();
var i;
for (i = 0; i < CP.length; i++) {
if (now < CP[i][0]) {
break;
}
}
if (i == 0) {
setTimeout(updateQuota, 1000);
} else if (i == CP.length) {
quota.innerHTML = 'Over ' + CP[i - 1][1];
} else {
var ts = CP[i - 1][0];
var bs = CP[i - 1][1];
quota.innerHTML = format(((now-ts) / (CP[i][0]-ts) * (CP[i][1]-bs)) + bs);
setTimeout(updateQuota, 1000);
}
}
function el(id) {
if (document.getElementById) {
return document.getElementById(id);
} else if (window[id]) {
return window[id];
}
return null;
}
var PAD = '.000000';
samo što ja i dalje ne kužim od kud on uzima varijablu za brojač, itd. Općenito kako stvar funkcionira...[/code]
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum