Raphaeljs 子字符串文本属性

编程入门 行业动态 更新时间:2024-10-27 16:31:05
本文介绍了Raphaeljs 子字符串文本属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道是否可以在 Raphael 中更改文本对象的子字符串的属性.例如,我想在下面的字符串神奇的巫师统治世界!"中加粗巫师"这个词.在拉斐尔文本对象中.我已经研究过使用 Raphael.print() 方法,我需要一些来自文本的属性用于代码的其他部分.

I was wondering if it's possible to change the attributes of a substring of the text object in Raphael. For example, I want to bold the word wizard in the following string "The magical wizard ruled the world!" in a raphael text object. I have looked at using the Raphael.print() method and I need some of the attributes from text for other portions of the code.

推荐答案

字体是在元素级别设置的,就像在常规 html 中一样.要将单独的字体或样式应用到特定单词,您需要将文本分成单独的元素.

Fonts are set at the element level, much like in regular html. In order to apply a separate font or style to a specific word, you would need to break your text into separate elements.

var start = paper.text(20, 20, "The magical "); start.attr({ "text-anchor": "start" }); var startBox = start.getBBox(); var bold = paper.text(startBox.width + startBox.x, 20, "wizard "); bold.attr({ "text-anchor": "start", "font-weight": "bold" }); var boldBox = bold.getBBox(); var end = paper.text(boldBox.width + boldBox.x, 20, "ruled the world!"); end.attr({ "text-anchor": "start" });

更多推荐

Raphaeljs 子字符串文本属性

本文发布于:2023-10-26 22:11:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531493.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   属性   文本   Raphaeljs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!