Increment integer by 1; every 1 second

百般思念 提交于 2019-11-30 22:11:18

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);
}

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.

var indexVariable = 0;
setInterval(function () {
    indexVariable = ++indexVariable % 360 + 1; // SET { 1-360 }
}, 1000);

Try:

var indexVariable = 0;
setInterval(
    function () {
        indexVariable = (indexVariable + 1) % 361;
    }, 1000}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!