如何将文本添加到 raphael js 元素 [英] How to add text to a raphael js element
本文介绍了如何将文本添加到 raphael js 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 raphael js 中向元素添加文本,我用
I want to add text to a element in raphael js, I have added text with
r.text(30, 20, "ellipse").attr({fill: color});
但是如何将此文本添加到
But how to add this text to
ec = r.ellipse(190, 100, 30, 20);
问候
推荐答案
Raphael 元素之间没有子/父关系,因此您将为它们设置相同的位置,例如
Raphael does not have child/parent relationship between elements, so you will set same position for them e.g.
ec = paper.ellipse(190, 100, 30, 20);
paper.text(190, 100, "ellipse").attr({fill: '#ff0000'});
因此,如果您想要带有文本的椭圆,请创建您自己的 JavaScript 对象来处理两者的定位.
So if you want a ellipse with text, create your own JavaScript object which handles positioning of both.
或替代方法是通过 set
对元素进行分组,例如
or alternate way is to group elements via set
e.g.
var eltext = paper.set();
el = paper.ellipse(0, 0, 30, 20);
text = paper.text(0, 0, "ellipse").attr({fill: '#ff0000'})
eltext.push(el);
eltext.push(text);
eltext.translate(100,100)
这篇关于如何将文本添加到 raphael js 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文