jquery-svg - SVG文本围绕中心旋转

标签 jquery-svg

我有以textContent“Design”和text-anchor为开头的文本,该文本已通过CSS转换为旋转45度。这样它就旋转了。问题是,我需要在旋转后调整文本的(x,y)位置,以在刻度之间显示文本,如预期图所示。我怎么能做到这一点。

结果:
http://imageshack.us/content_round.php?page=done&l=img404/2711/result1h.png

预期的:
http://imageshack.us/content_round.php?page=done&l=img266/5138/expected1.png

    <svg>
    <text x="100" y="100" width="64" height="16" fill="black" transform="rotate(45,100,100)" text-anchor="start">Design</text>
    </svg>

谢谢
高里

最佳答案

文本需要水平和垂直居中,因此旋转不会移动它:

<text x="100" y="50" text-anchor="middle"
    dominant-baseline="central" transform="rotate(0, 100, 50)"></text>
text-anchor将文本水平对齐dominant-baseline垂直对齐文本

svg {
    width: 200px; height: 100px;
    text-align: center;
    border: solid 1px blue;
    font-family: monospace;
}
<svg>
    <text x="100" y="50" text-anchor="middle" dominant-baseline="central" transform="rotate(180, 100, 50)">
       Hello World
   </text>
    <text x="100" y="50" text-anchor="middle" dominant-baseline="central" transform="rotate(0, 100, 50)">
       Hello World
   </text>
</svg>


示例:http://jsfiddle.net/e4bAh/131/

关于jquery-svg - SVG文本围绕中心旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16726115/

相关文章:

javascript - 鼠标悬停时的动画/响应式/实时图标。给出的例子

svg - svg 文本的文本编辑器

jQuery 动画 SVG 元素

svg - 应用于作为 svg 元素的 el 的主干事件

twitter-bootstrap - Bootstrap 工具提示未显示在 SVG 悬停上

svg - svg 中的剪辑路径和变换组合

html - 使用svg进行图像注释

jquery - 基思·伍德 JQuery SVG : clone() followed by change() not working

javascript - 两个单独路径加入 SVG 时的斜接效果