繁体   English   中英

FireFox中的JavaScript Canvas问题,在Chrome中正常运行

[英]JavaScript Canvas Issue in FireFox, works fine in Chrome

我是刚接触堆栈的新手; 但是发现这里讨论的许多主题对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();
       }

window.history是保留的对象: http : //www.w3schools.com/jsref/obj_history.asp 尝试将所有出现的window.history替换为window._history (或其他名称)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM