最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting text background color in Raphael - Stack Overflow

programmeradmin2浏览0评论

I am using Raphael-js to position text on a canvas. Is it possible to have a background color for the text? I would like different text elements to have different backgrounds colors.

Thanks,

I am using Raphael-js to position text on a canvas. Is it possible to have a background color for the text? I would like different text elements to have different backgrounds colors.

Thanks,

Share Improve this question asked Jun 8, 2011 at 11:00 FarhatFarhat 1,2132 gold badges12 silver badges19 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13

Yes, there is no way to specify background for text, here is how to create rectangle that will serve as a background:

var text = canvas.text(p.x, p.y, poly.title).attr(textAttr);
var box = text.getBBox();
var rect = canvas.rect(box.x, box.y, box.width, box.height).attr('fill', 'black');
text.toFront();

The background of text is known as "fill" and can be applied using the attr function as follows:

paper.text(50, 50, "Example").attr("fill", "#000000");

For a full listing of the properties, see the Raphael Documentation

发布评论

评论列表(0)

  1. 暂无评论