- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Raphaël 文本对象,我想围绕一定距离之外的轴旋转,并相应地旋转文本,使其保持水平。我知道使用 SVG 变换矩阵这是可能的,但是 Raphaël has stated that they won't be a part of the toolkit anytime soon 的作者。这是我想做的一些代码:
txt_obj = paper.text(100, 100, "Hello!");
txt_obj.rotate(90, 100, 200); // rotate text so it is sideways at (200,200)
txt_obj.rotate(-90); // rotate text back to horizontal
不幸的是,第二个旋转命令消除了第一个旋转命令完成的平移和旋转。
如果我直接使用 SVG,我可以这样做:
<g transform="rotate(90, 100, 200)">
<text x="100" y="100" transform="rotate(-90, 100, 100)">Hello!</text>
</g>
但是,我不相信 Raphaël 支持 svg g
元素。
理想情况下,我希望为该操作设置动画,但现在我会一步一步地进行。
最佳答案
这是一个老问题,但我只是努力解决它,所以我想分享我的答案。
您可以直接访问 SVG 对象,甚至在 Raphael 调用中也是如此:
this.node.getAttribute('x')
或
this.node.getAttribute('transform')
第二个是我们需要的东西。使用 Raphael 旋转文本的麻烦在于它所做的只是在 SVG 中设置变换:
<text x="600" y="606.240234375" text-anchor="middle" style="text-anchor: middle;
font: normal normal normal 10px/normal Arial; font-family: Arial; font-weight: 900;
font-size: 18px; " font="10px "Arial"" stroke="none" fill="#000000"
font-family="Arial" font-weight="900" font-size="18px" transform="rotate(45 600 600)">
<tspan style="-webkit-user-select: none; cursor: pointer; ">FOOBAR</tspan></text>
多次调用 .rotate() 会覆盖之前的设置,因此最终在 SVG 转换中只调用一次旋转。但是我们可以通过直接访问属性来添加我们自己的转换。变换似乎是以相反的顺序执行的(或者其他什么——老实说,我并没有想太多),所以如果你想让它先进行,你可以把额外的旋转放在最后:
<script>
(function (raphael) {
$(function () {
var paper = raphael("raphael_div", 500, 500);
upside_down_text = paper.text(100,100,'UPSIDE DOWN')
.attr('font-family','Arial')
.attr('font-size','24px');
upside_down_text.rotate(25,250,250); // rotate using Raphael
// But first we want to rotate 180 degrees.
height = upside_down_text.getBBox().height;
upside_down_text.node.setAttribute('transform',
upside_down_text.node.getAttribute('transform')+
' rotate(180 '+
upside_down_text.node.getAttribute('x')+
' '+
(upside_down_text.node.getAttribute('y')-(height/2))+
')');
});
})(Raphael.ninja());
</script>
<div id="raphael_div"></div>
关于javascript - 如何在 Raphael 文本对象上应用多个旋转变换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3067129/
使用 Raphael,我可以使用以下代码获取对元素的 DOM 对象的引用: element.node 如何获取链接到 DOM 对象的元素?换句话说,上面函数的逆函数(例如 DOMobject.ele
我一直在尝试在集合中嵌套集合,但无济于事。 这个概念来自 photoshop,您可以在其中将元素分组到一个文件夹/集中,然后将它们嵌套到另一个文件夹/集中。 我正在尝试轻松地将两组或更多组合并为一组,
我正在尝试绘制一个矩形,每条边(不在角落)有 4 个连接点。像这样: 因为稍后我需要对它们使用鼠标事件。 最佳答案 是this你在找什么? 关于raphael - 使用 Raphael 绘制带连接点的
您好,我正在按照此页面上的教程进行操作: http://net.tutsplus.com/tutorials/javascript-ajax/an-introduction-to-the-raphae
var paper = new Raphael("holder", 320, 200); function testPaper(){
使用 Raphael 2.0 ,我试图以相对于集合中所有对象的方式将变换应用于一组对象。但是,我得到的效果是,无论集合中的其他对象如何,变换都单独应用于每个项目。 例如:http://jsfiddle
我想随着鼠标在纸上的移动画一条线。我只知道如何使用 path 画线。但是想知道是否有人有想法与 mousemove 一起画线。请帮我解决这个问题。 最佳答案 这里有一个使用 raphael 的例子的链
我需要使用 raphael.js 绘制各种大小的同心圆弧。我试图理解背后的代码 http://raphaeljs.com/polar-clock.html ,这与我想要的非常相似,但是,没有评论,很难
我想让堆叠条形图的每个部分(在我的例子中是水平的)都可以单击到特定的超链接(基本上是“向下钻取”)。我认为 g.bar.js 中没有这个功能,但是有人这样做过或者可以为我指出正确的方向吗?在点图上也很
我想用按钮点击事件显示/隐藏我的 raphael svg 图 请知道该怎么做的人。请帮助我 我尝试通过这种方式来做,但它不起作用。 var p = Raphael(900,70,200,200); p
我找不到简单答案的简单问题。 如何查看 Raphael 元素的完整当前人类可读(非矩阵)变换状态,无论该元素的变换状态是否设置或如何设置? 例如,使用 element.transform() 不会为您
我一直在使用raphael.draggable与我目前正在 build 的项目。我已经升级到raphael 2.0现在插件似乎停止工作了,我不知道为什么。 我得到的错误信息是: paper.dragg
我需要检索在 Raphael 中绘制的路径末端的 X/Y 坐标。我找到了一种通过在 SVG 浏览器中自省(introspection)路径的方法,但这种方法在 VML 浏览器中不起作用。 例子: va
我正在将 Raphael 与 Meteor 一起使用,但遇到了问题。我正在创建一个 paper通过使用 var paper = Raphael("paper", 800, 600);如果我将此代码放在
我正在研究项目要使用什么图形,Raphael.js 成为了最佳竞争者。但是,在阅读示例代码和文档时,它显示 Raphael 创建了一个 Canvas (通过 homepage 上的 paper 变量)
出于某种原因,我可以使用矩形变量而不是圆形来使用它。 目前,此代码允许两个圆圈独立拖动,但不能一起拖动 有人知道如何解决这个问题或其他方法吗? addIntermediateSymbol = func
我很难在 Raphael.js 中调整 Canvas 的大小。我以为我可以简单地使用: var paper = Raphael("paper", 100, 100); 这将使用 ID“纸”创建一个宽度
我想使用 raphael.js 渲染 ember.js View 或 d3.js .我的理解是it is possible to do this ,但在阅读了所有文档和谷歌搜索后,我似乎无法弄清楚如何
我认为所有这些基本上都非常酷,并且熟悉它们的明显差异(SVG 与 Canvas ),但我不确定它们在开发时间、性能和支持方面的潜在差异、优势或限制。 最佳答案 我体验过 Processing 作为一个
我最近使用 d3.js 实现了一些数据可视化,我现在正试图让它适用于 Internet Explorer 浏览器版本 7 及更高版本。让它工作的常见建议是将 d3.js 与 raphael.js 结合
我是一名优秀的程序员,十分优秀!