<div>
lt;span class="moneyCounter"></span> raised so far.
</div>
<script type="text/javascript">
var setCounter = function(){
var counterValue =
(new Date().getTime() - new Date('01/01/2011').getTime())/(1000*60*6);
$('.moneyCounter').text(counterValue);
}
setInterval(setCounter,10000);
setCounter();
</script>
这将使该值每十秒增加 1。您可能想要使用更令人兴奋的函数,甚至可能是间隔的随机更新间隔。
If you want the counter to increase gradually between sessions, and avoid using some kind of server side state, maybe you can base the counter value on a function of time?
<div>
lt;span class="moneyCounter"></span> raised so far.
</div>
<script type="text/javascript">
var setCounter = function(){
var counterValue =
(new Date().getTime() - new Date('01/01/2011').getTime())/(1000*60*6);
$('.moneyCounter').text(counterValue);
}
setInterval(setCounter,10000);
setCounter();
</script>
This will raise the value with 1 every ten seconds. You might want to use a more exciting function, and maybe even a random update interval for the interval.
发布评论
评论(1)
如果您希望计数器在会话之间逐渐增加,并避免使用某种服务器端状态,也许您可以将计数器值基于时间函数?
这将使该值每十秒增加 1。您可能想要使用更令人兴奋的函数,甚至可能是间隔的随机更新间隔。
If you want the counter to increase gradually between sessions, and avoid using some kind of server side state, maybe you can base the counter value on a function of time?
This will raise the value with 1 every ten seconds. You might want to use a more exciting function, and maybe even a random update interval for the interval.