canvas元素在单击后变为不可见

时间:2013-09-12 07:43:10

标签: javascript jquery html canvas fabricjs

我正在尝试在画布上编写撤消/重做功能。我正在使用fabric-js绘制对象。撤消?重做工作正常,但问题是在调用撤消/重做功能后,如果我点击画布元素变为不可见。我试过canvas.renderAll()我仍然遇到问题。

撤消::

的步骤
  1. 在元素绘制之前我将canvas.toDataURl()保存在变量数组中。

    2.单击撤消按钮时,我使用清除布料方法清除画布,然后使用Previous`toDataUrl()将变量Array绘制到画布上。

  2. 代码::

         function undoDrawOnCanvas() {
            console.log('inside undodrawn');
            // If we have some restore points
            if (restorePoints.length > 0) {
                // Create a new Image object
    
                var oImg = new Image();
                // When the image object is fully loaded in the memory...
                oImg.onload = function() {
    
                    //Saving point for Redo
                    c_redo=document.getElementById("design_text").toDataURL("image/png");
    
                    canvas.clear();
    
                    // Get the canvas context
                    var canvasContext = document.getElementById("design_text").getContext("2d");
                    // and draw the image (restore point) on the canvas. That would overwrite anything
                    // already drawn on the canvas, which will basically restore it to a previous point.
                    canvasContext.drawImage(oImg, 0, 0);
                }
                // The source of the image, is the last restoration point
                oImg.src = restorePoints.pop();
    
            }
        }  
    

0 个答案:

没有答案