【发布时间】:2016-10-14 00:33:34
【问题描述】:
我很难将 FarbicJS 元素带到画布的前面。
在浏览了几次网页后,我发现了这篇文章:Control z-index in Fabric.js 但是,它似乎对我的代码完全没有影响。
编辑:this topic 也带来了一些其他的解决方案,但也没有效果。
我可能犯了一个愚蠢的错误,但我不知道在哪里。这是我的代码(至少是相关部分):
//first image, well displayed and functionnal
fabric.Image.fromURL(sourceImg, function(img){
//don't pay attention to following properties
img.left = YYY
img.top = XXX
img.width = whatever
img.height = whatever
img.rega = something
//big animation part
img.on('mouseover', function(){
//blabla
});
that.canvas.add(img);
});
//second image (text), not displayed
var myText = new fabric.Text("SI REGA2", {
//some properties...
left: YYY // Here coordonnates of the text are the same
top: XXX // than first image's coordonnates.
selectable: false,
hasControls: false,
hasBorders: false,
fontSize: 20
});
this.canvas.add(myText); //adding text to the canvas...
this.canvas.bringToFront(myText); //... and bringing back to the front in order to place it over the first image
控制台没有错误,所以我认为一切顺利,但是没有显示文本。或者至少在第一张图片下方。
我该怎么办?
【问题讨论】:
-
你使用网页浏览器的 F12 吗?
-
是的,很棒的工具。在这里它没有出现,但我尝试
console.log(myText)并且对象似乎没问题。这就是让我认为文本已添加到画布但低于图像的原因。 -
嗯...那我只能祝你好运了!或提供小型工作样本以隔离您的错误
标签: javascript fabricjs