1
How to know if the canvas is ready?
I’m using the library fabricjs, that creates a complex element structure within a canvas, but I’d like to call a callback function after the canvas had all the complex elements loaded.
html2canvas does something similar, but it doesn’t work with fabricjs:
html2canvas($('#my_canvas'), {
onrendered: function(canvas) {
//SIMILAR A ISSO
}
});
What I can get is the total elements of my canvas:
var totalItens = canvas.getObjects().length;
And I’m processing a time based on quantity, the problem is that there may be a single very complex item, and the action may not behave well while still being loaded in the browser:
var calc = (totalItens * 400),
tempoDoProcesso = (calc) > 6000 ? 6000 : calc
setTimeout({
//faço a ação...
}, tempoDoProcesso);
The canvas starts to hang when it has many items on the screen... and so it is impossible to do any event before the process has finished.
Have you read the documentation? http://fabricjs.com/events
– Maury Developer
canvas.on("after:render", function() {})
. Source: https://github.com/fabricjs/fabric.js/wiki/Working-with-events– Maury Developer
I read yes, but I did not find the information very clear, I had difficulties in finding the solution, a colleague of mine also searched with me here and did not find... if you notice in this link of Events, he is the last of the list, passed beaten. In fact much of the events I have used in lib, I had to hunt around...
– Ivan Ferrer