在setTimeout内部和函数内调用一个函数 [英] calling a function inside setTimeout and inside a function
本文介绍了在setTimeout内部和函数内调用一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b函数animation(){
setTimeout(
function() {
requestAnimationFrame(animation);
if(player.currentFrame == player.frames){
player.currentFrame = 0;
} else {
player.currentFrame ++ ;
}
}
,1000/15);
}
我试图用这段代码调用它
animation( fps);
我试过这样:
function animation(fps){
setTimeout(
function(){
requestAnimationFrame(animation);
if(player.currentFrame == player.frames){
player.currentFrame = 0;
} else {
player.currentFrame ++;
}
}
,1000 / fps);
}
并尝试用 animation(30)
但它不起作用。我尝试过这样的搜索主题,但其中没有一个是我想要的。
任何帮助将不胜感激! :
解决方案
您是否尝试过这种语法?
函数动画(fbs){
requestAnimationFrame(动画);
if(player.currentFrame == player.frames){
player.currentFrame = 0;
} else {
player.currentFrame ++;
}
setTimeout(function(){animation(fbs)},1000 / fbs);
}
我将代码从 setTimeout('animation( fbs)',1000 / fbs);
至 setTimeout(function(){animation(fbs)},1000 / fbs);
basically I have written a function:
function animation(){ setTimeout( function(){ requestAnimationFrame(animation); if (player.currentFrame == player.frames) { player.currentFrame = 0; } else { player.currentFrame++; } } , 1000 / 15); }
and I'm trying to call it with this code
animation(fps);
I tried making it like this:
function animation(fps){ setTimeout( function(){ requestAnimationFrame(animation); if (player.currentFrame == player.frames) { player.currentFrame = 0; } else { player.currentFrame++; } } , 1000 / fps); }
and tried to call it with animation(30)
but it didn't work. I tried search topic like this but non of them is excatly what I want.
Any help would be appreciated! :)
解决方案
Did you tried this syntax
function animation(fbs){
requestAnimationFrame(animation);
if (player.currentFrame == player.frames) {
player.currentFrame = 0;
} else {
player.currentFrame++;
}
setTimeout(function(){animation(fbs) }, 1000 / fbs);
}
I changed the code from setTimeout('animation(fbs)', 1000 / fbs);
to setTimeout(function(){animation(fbs) }, 1000 / fbs);
这篇关于在setTimeout内部和函数内调用一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文