简体   繁体   English

Fabric.js中的动画图像

[英]Animating image in Fabric.js

Loving fabric and trying to get to grips with it all. 爱织物,并试图掌握一切。

My overall goal is to display a well being drilled. 我的总体目标是展示一口井。 I have many many questions but the first of which is 'how can i animate the image object?' 我有很多问题,但第一个问题是“如何为图像对象设置动画?”

I have: 我有:

var drillBit = new fabric.Image.fromURL('assets/images/drillBit.jpg',function(img){
    img.scale(0.5).set({left:400, top:0});
    canvas.add(img);
});

and then I call: 然后我打电话给:

(function animate() {
    canvas.item(9).top+=1;
    canvas.renderAll();
    fabric.util.requestAnimFrame(animate);
})();

If i replace the item index with another so that it represents text or a rect it works fine but nothing when i select the image. 如果我用另一个替换项目索引,以便它表示文本或矩形,则可以正常工作,但是当我选择图像时什么也没有。 Can someone explain please? 有人可以解释一下吗?

Thanks 谢谢

Kangax answered this on the Google group. Kangax在Google网上论坛上回答了这个问题。

Solution is to: 解决方案是:

var drillBit = new fabric.Image.fromURL('assets/images/drillBit.jpg',function(img){
img.scale(0.5).set({left:400, top:0});
canvas.add(img);
//animate the drill
(function animate() {
    img.top+=1;
    canvas.renderAll();
    fabric.util.requestAnimFrame(animate);
})();
});  

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

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