0
我想提出一个奇怪的块体运动的事情,但在它移动的10倍,它说:是否可以删除最大调用堆栈大小?
Uncaught RangeError: Maximum call stack size exceeded
而我的目的是要让它动的整个时间,这里是代码BTW:
<html>
<head>
<title>Look - The game</title>
</head>
<body>
<div id="square" style="position:absolute; width:5px; height:5px; background:black"></div>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
var square = document.getElementById("square");
var duration = 1000;
var steps = 1;
function movesquare(){
var randomtop = Math.floor(Math.random() * screen.height);
var randomleft = Math.floor(Math.random() * screen.width);
$(square).animate({marginTop:randomtop, marginLeft:randomleft}, duration, movesquare);
duration -= steps;
steps = steps * 2;
}
movesquare();
</script>
</body>
你有使用递归的原因吗?也许这是无意的?这是你的堆栈问题的原因。 – 2014-12-07 15:49:51
你正在做错什么...! – GOD 2014-12-07 15:50:14
'超出最大调用堆栈大小'表示您有一种_endless loop_,并且如果浏览器不会停止您的脚本,则在这种情况下,您的浏览器很可能会变得无响应。 – 2014-12-07 15:50:32