html 画布 zindex
如何更改画布内元素的 zindex?
示例代码:
fabric.Image.fromURL('http://nocookie.net/bw.jpg', function(image) {
image.set('left', 200).set('top', 250);
canvas.add(image);
});
var helloWorld = new fabric.Text('Hello world!', {
left: 0,
top: 0,
fontfamily: 'delicious_500',
zindex: 10
});
canvas.add(helloWorld);
使用fabric.js 库。
供将来参考:
fabric.Element.html#bringForward
How do I change the zindex of an element inside a canvas?
Example code:
fabric.Image.fromURL('http://nocookie.net/bw.jpg', function(image) {
image.set('left', 200).set('top', 250);
canvas.add(image);
});
var helloWorld = new fabric.Text('Hello world!', {
left: 0,
top: 0,
fontfamily: 'delicious_500',
zindex: 10
});
canvas.add(helloWorld);
Using the fabric.js library.
For future reference:
fabric.Element.html#bringForward
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我根本无法让这该死的东西工作,但这是我对发生的事情的猜测:
因为图像是在文本之后添加到画布上的,所以我假设 Fabric 的行为就像画布通常所做的那样:稍后添加的内容将绘制在已经存在的内容之上。 ...即使您为文本指定了 z 索引。
请记住,我无法让它发挥作用,就放弃了。所以我完全有可能完全错了。如果是这样,我有另一个理论:
您确定 zindex 是正确的属性吗?如果是,那么也尝试在图像上设置它:
如果您不确定,那么...就这样。
I can't get the dang thing working at all, but here's my guess as to what's happening:
Because the image is added to the canvas after the text, I'm assuming that Fabric is acting just as the canvas normally would: things that are added later are drawn on top of things that are already there. ...Even though you gave the text a z-index.
Remember, I couldn't get it to work and just gave up. So it's entirely possible I'm totally, completely wrong. If that is the case, I have another theory:
Are you sure that
zindex
is the correct property? If you are, then try setting it on the image, as well:And if you aren't sure, then... there you go.
从 Fabric.js 版本 1.1.4 开始,可以使用 zIndex 操作的新方法:
我希望这就是您想要的:
http ://jsfiddle.net/Kienz/RRv3g/
Since fabric.js version 1.1.4 a new method for zIndex manipulation is available:
i hope this is what you want:
http://jsfiddle.net/Kienz/RRv3g/