Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在每个解决方案中暂停执行一段时间,以使动画可见_Javascript_Jquery - Fatal编程技术网

Javascript 在每个解决方案中暂停执行一段时间,以使动画可见

Javascript 在每个解决方案中暂停执行一段时间,以使动画可见,javascript,jquery,Javascript,Jquery,我已经在javascript中使用回溯编码了N-Queen问题 我想做什么? 我希望在每次脚本到达解决方案时,都能看到脚本执行一秒钟,并使用动画显示解决方案 有什么问题吗? 代码执行如此之快,以至于我看不到任何颜色转换 这是我的代码的一部分(我想在这里发现一下脚本的执行情况)。 有关完整代码,请参阅 函数placeQueen(行){ 对于(var i=0;i感谢@bergi和所有有价值的建议 我使用数组存储所有结果,然后使用setInterval函数模拟结果 var solutionArray

我已经在javascript中使用回溯编码了N-Queen问题

我想做什么? 我希望在每次脚本到达解决方案时,都能看到脚本执行一秒钟,并使用动画显示解决方案

有什么问题吗? 代码执行如此之快,以至于我看不到任何颜色转换

这是我的代码的一部分(我想在这里发现一下脚本的执行情况)。 有关完整代码,请参阅

函数placeQueen(行){

对于(var i=0;i感谢@bergi和所有有价值的建议 我使用数组存储所有结果,然后使用setInterval函数模拟结果

var solutionArray = [];

// run the algorithm and do
solutionArray.push(tempResult);
// on every step

var counter=0;
var myVar = setInterval(function(){ 
    simulate(solutionArray[counter++]);
    if(counter>=92){
        clearInterval(myVar);
    }
    setTimeout(function(){
        removeSimulation(solutionArray[counter]);
    },600);
}, 1000);

是指向完整代码的链接

在Firefox或Chrome中的调试器中打开代码。这样,您就可以一步一步地了解所发生的事情。@Norbert是的,我可以使用断点来完成,但我想在不使用debbuger的情况下向其他人显示此模拟。我尝试使用setTimeout函数,但它不起作用。您的问题应该是包含足够的代码以重现错误,即使有指向小提琴的链接。@BSMP my code不包含任何错误。我只想在到达print()函数时停止代码的执行一秒钟。当print()时,您可以使用断点在线查看my函数被调用。@BSMP当您放置断点时,它看起来是这样的。您能从您的小提琴中删除那些
print()
语句吗(并更新链接)?
var solutionArray = [];

// run the algorithm and do
solutionArray.push(tempResult);
// on every step

var counter=0;
var myVar = setInterval(function(){ 
    simulate(solutionArray[counter++]);
    if(counter>=92){
        clearInterval(myVar);
    }
    setTimeout(function(){
        removeSimulation(solutionArray[counter]);
    },600);
}, 1000);