2013-10-13 81 views
1

我從JSON對象加載畫布並調用toDataURL但我需要一個回調,它將在畫布加載後執行,因爲如果畫布上有圖像,toDataURL函數返回因爲在圖像加載之前調用了空白頁面。Fabric.js - 如何爲畫布加載事件給出回調

canvas.loadFromJSON(json); 

// I need an event handler here which will be executed after canvas is loaded 

var dataURL = canvas.toDataURL(); 
+1

閱讀本手冊! http://fabricjs.com/docs/fabric.Canvas.html#loadFromJSON – ComFreek

+0

我認爲這個問題應該鏈接到:http://stackoverflow.com/questions/18311448/loadfromjson-function-is-loading-objects-filled -with圖案僅-後點擊 – coolfeature

回答

3

您可以使用回叫loadFromJSON(URL,回調)

<pre> 
     canvas.loadFromJSON(url, function() { 
      //first render 
      canvas.renderAll.bind(canvas); 
      //before call to zoomOut(); 
      zoomOut(); 
     }); 



function zoomOut() { 
     var objects = canvas.getObjects(); 
     console.debug(objects); 
    ...... 
    }