我正在尝试制作一个基本(非动画)老虎机,但堆栈大小出现错误。
我希望有人可以解释原因是什么=/
我的错误:
Uncaught RangeError: Maximum call stack size exceeded
代码:
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback, element){
window.setTimeout(callback, 1000 / 60);
};
})();
var img_array = new Array('fire','life','lightning','rain','snow','sound','sun');
function roll(start_time){
var seconds_passed = new Date().getTime() / 1000 - start_time ;
if(seconds_passed < 3){
slot = 1;
while(slot < 4){
randno = Math.floor(Math.random()*img_array.length);
document.getElementById("slot"+slot).innerHTML = '<img src="'+img_array[randno]+'.png"/>';
slot++;
}
requestAnimFrame(roll(start_time));
} else {
document.getElementById("start").innerHTML = 'Roll The Slots Again?';
document.getElementById("start").onclick = function(){start(); };
}
return false;
}
function start(){
start_time = new Date().getTime() / 1000;
document.getElementById("start").innerHTML = 'Processing......';
roll(start_time);
}
window.onload = function(){
document.getElementById("start").innerHTML = 'Roll The Slots';
document.getElementById("start").onclick = function(){start(); };
}
我的错误在哪里?