我是筹码流量新手;但是已经发现这里讨论的许多主题对Web应用程序的开发非常有帮助。
但是,这次我很难过。我在JavaScript中编写了一些简单的函数,以便在使用新的HTML5画布时添加撤消/重做功能。我写的代码在Chrome中运行良好,但在Firefox中不起作用;我想我已经将问题隔离到了我将图像对象放入数组的代码行(在Chrome中正常工作)。我研究了这个,我找不到任何理由为什么这在FireFox中不起作用。任何帮助将不胜感激。
function push()
{
window.cStep++;
if (window.cStep < window.history.length) { window.history.length = window.cStep; }
var imageData = window.context.getImageData(0, 0, canvas.width, canvas.height);
alert(imageData);
window.history[window.cStep] = imageData;
document.title = "Step [" +window.cStep + "] Of A Possible [" + (window.history.length -1) + "]";
}
function undo()
{
if (window.cStep > 0) {
window.cStep--;
window.context.putImageData(window.history[window.cStep], 0, 0);
document.title = "Step [" +window.cStep + "] Of A Possible [" + (window.history.length -1) + "]";
if(window.cStep ==0)
{document.getElementById('middle_centre_canvas').style.opacity = 0.6;}
else
{document.getElementById('middle_centre_canvas').style.opacity = 1;}
}
}
function redo()
{
if (window.cStep < window.history.length-1) {
window.cStep++;
window.context.putImageData(window.history[window.cStep],0,0);
document.title = "Step [" +window.cStep + "] Of A Possible [" + (window.history.length -1) + "]";
if(window.cStep >0)
{document.getElementById('middle_centre_canvas').style.opacity = 1;}
}
}
function loadyLoader(){
window.canvas = document.getElementById("canvas");
window.context = window.canvas.getContext('2d');
window.history = new Array();
window.cStep = -1;
push();
}
答案 0 :(得分:0)
window.history是一个保留对象:http://www.w3schools.com/jsref/obj_history.asp。 尝试用 window._history (或其他名称)替换所有 window.history 出现次数。