How to change the image of the fabric.Image object attribute src?

前端 未结 3 518
生来不讨喜
生来不讨喜 2021-02-13 17:23

How can I change the image of the fabric.Image object attribute src, if I have already made an animation?

3条回答
  •  感情败类
    2021-02-13 17:43

    You can use .setElement() to change the image.

    For example, let's say you have a fabricJS image object called myFabricObect.

    Then, if you have an html image element on your page, you can load your myFabricObject with the "newImage" like this:

    myFabricObject.setElement(document.getElementById("newImage"));
    

    You could also create a javascript Image() and assign that to myFabricObject:

    var img=new Image();
    img.onload=function(){
        myFabricObject.setElement(img);
    }
    img.src="myNewImage.png";
    

提交回复
热议问题