jQuery或Javascript连续计数器

jQuery或Javascript连续计数器

本文介绍了jQuery或Javascript连续计数器(计数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找一个我可以理想输入起始编号和开始日期的脚本,然后根据我设置的速率继续增加每秒1次。理想情况下,该脚本会根据当前时间和开始时间之间的差异来计算它应该是什么数字。



这意味着它看起来像是在显示实时计数。 / p>

理想情况下,就像



有没有人可以分享他们可以分享的链接或插件或解决方案?



如果数字可以用数字图像替换甚至更好,但一个起点将非常感激。



谢谢

解决方案

如果你想要一个只有javascript的解决方案,你可以像这样制作一个div:

 < div id =counter>< / div> 

然后在页面的某处使用以下脚本:

  var START_DATE =新日期(2010年7月27日13:30:00); //在这里输入开始日期
var INTERVAL = 1; //秒数
var INCREMENT = 2; //每个刻度增加
var START_VALUE = 9001; //当它是开始日期时的初始值
var count = 0;

window.onload = function()
{
var msInterval = INTERVAL * 1000;
var now = new Date();
count = parseInt((now - START_DATE)/ msInterval)* INCREMENT + START_VALUE;
document.getElementById('counter')。innerHTML = count;
setInterval(count + = INCREMENT; document.getElementById('counter')。innerHTML = count;,msInterval);
}

你可以使用类似于theuuks的技术来获取图像,或者你可以用CSS设置计数器div的样式。


Looking for a script that I can ideally enter a starting number and a start date, which then continues to increment based on a rate I set e.g. 1 per second. The script would ideally calculate what number it should be on based on the difference between the current time and start time.

It's meant to look like it's showing a live count.

Ideally, something like the counter on http://sendgrid.com/

Has anyone got a link or plugin or solution they can share?

If the numbers can be replaced with images of numbers even better, but a starting point would be much appreciated.

Thanks

解决方案

If you want a javascript only solution, you can just make a div like this:

<div id="counter"></div>

And then use the following script somewhere on the page:

var START_DATE = new Date("July 27, 2010 13:30:00"); // put in the starting date here
var INTERVAL = 1; // in seconds
var INCREMENT = 2; // increase per tick
var START_VALUE = 9001; // initial value when it's the start date
var count = 0;

window.onload = function()
{
 var msInterval = INTERVAL * 1000;
 var now = new Date();
 count = parseInt((now - START_DATE)/msInterval) * INCREMENT + START_VALUE;
 document.getElementById('counter').innerHTML = count;
 setInterval("count += INCREMENT; document.getElementById('counter').innerHTML = count;", msInterval);
}

You can use a technique similar to that of thenduks to get images, or you could just style the counter div with CSS.

这篇关于jQuery或Javascript连续计数器(计数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 03:42