将整数递增1;每1秒钟 [英] Increment integer by 1; every 1 second

查看:117
本文介绍了将整数递增1;每1秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是创建一段代码,每1秒递增一个数字:

My aim is to create identify a piece of code that increments a number by 1, every 1 second:

我们将调用我们的基数indexVariable,然后我想要to:indexVariable = indexVariable + 1每1秒;直到我的indexVariable达到360 - 然后我希望它重置为1并再次执行循环。

We shall call our base number indexVariable, I then want to: indexVariable = indexVariable + 1 every 1 second; until my indexVariable has reached 360 - then I wish it to reset to 1 and carry out the loop again.

如何在Javascript中实现这一目标? - 如果它有所作为我使用Raphael框架。

How would this be possible in Javascript? - if it makes a difference I am using the Raphael framework.

我对JavaScript计时事件和Raphael延迟函数进行了研究 - 但这些似乎不是答案 - 任何人都可以提供帮助吗?

I have carried out research of JavaScript timing events and the Raphael delay function - but these do not seem to be the answer - can anyone assist?

推荐答案

出于这个原因,您可以使用 setInterval()

You can use setInterval() for that reason.

var i = 1;

var interval = setInterval( increment, 1000);

function increment(){
    i = i % 360 + 1;
}

编辑:您的后续问题的代码:

edit: the code for your your followup-question:

var interval = setInterval( rotate, 1000);

function rotate(){
      percentArrow.rotate(1,150,150);
}

我不完全确定你的旋转是如何工作的,但你可能有将度数存储在var中并增加那些var,就像上面的例子一样。

I'm not entirely sure, how your rotate works, but you may have to store the degrees in a var and increment those var too like in the example above.

这篇关于将整数递增1;每1秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆