- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 svg.js 将文本放置到路径上
这是我的 fiddle : https://jsfiddle.net/Byteschmiede/ytz67egn/1/
var draw = SVG().addTo('body').size(500, 500)
draw.svg(`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="100%" height="100%" viewBox="0 0 4725 2363" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<path id="text1326" d="M2362.2,952.109C2548.36,773.615 2727.44,622.128 2899.46,497.647C3071.47,370.823 3216.39,286.272 3334.21,243.993C3452.02,201.721 3580.45,180.583 3719.47,180.58C4011.66,180.583 4247.3,278.051 4426.39,472.986C4607.82,665.577 4698.54,899.267 4698.55,1174.06C4698.54,1361.95 4658.48,1535.75 4578.37,1695.46C4498.25,1855.16 4383.97,1976.12 4235.52,2058.32C4089.42,2140.53 3920.94,2181.63 3730.08,2181.62C3482.66,2181.63 3265.87,2128.78 3079.72,2023.09C2895.92,1917.4 2656.75,1717.77 2362.2,1424.19C2055.87,1727.16 1811.99,1929.15 1630.55,2030.14C1449.11,2131.13 1238.21,2181.63 997.866,2181.62C691.537,2181.63 452.365,2086.51 280.351,1896.27C110.692,1706.03 25.862,1465.29 25.863,1174.06C25.862,901.616 115.404,667.926 294.489,472.986C475.929,278.051 712.744,180.583 1004.94,180.58C1146.32,180.583 1275.92,201.721 1393.74,243.993C1511.55,286.272 1655.29,370.823 1824.95,497.647C1996.97,622.128 2176.05,773.615 2362.2,952.109M2591.95,1170.53C2841.72,1417.14 3046.73,1585.07 3206.96,1674.32C3369.55,1761.22 3530.96,1804.67 3691.2,1804.67C3891.49,1804.67 4048.18,1745.95 4161.29,1628.52C4274.4,1508.74 4330.95,1364.3 4330.95,1195.19C4330.95,1009.65 4274.4,856.992 4161.29,737.208C4050.54,615.082 3903.27,554.017 3719.47,554.014C3615.79,554.017 3515.64,572.806 3419.04,610.382C3322.42,645.614 3206.96,709.027 3072.65,800.622C2938.33,889.873 2778.1,1013.18 2591.95,1170.53M2132.46,1170.53C1962.8,1027.27 1810.81,909.836 1676.5,818.237C1542.19,724.294 1424.37,657.357 1323.05,617.428C1221.72,577.503 1110.97,557.54 990.797,557.537C818.78,557.54 676.22,617.43 563.115,737.208C450.009,856.992 393.456,1009.65 393.457,1195.19C393.456,1324.37 422.911,1433.58 481.82,1522.83C540.729,1612.08 612.598,1681.37 697.428,1730.68C784.613,1780.01 893.006,1804.67 1022.61,1804.67C1192.27,1804.67 1357.21,1760.05 1517.45,1670.8C1677.68,1581.55 1882.68,1414.79 2132.46,1170.53" style="fill:none;fill-rule:nonzero;stroke:black;stroke-width:1px;"/>
<path id="textCurve3" d="M294.489,472.986C475.929,278.051 712.744,180.583 1004.94,180.58C1146.32,180.583 1275.92,201.721 1393.74,243.993C1511.55,286.272 1655.29,370.823 1824.95,497.647" style="fill:none;fill-rule:nonzero;stroke:black;stroke-width:1px;"/>
<path id="textCurve2" d="M2899.46,497.647C3071.47,370.823 3216.39,286.272 3334.21,243.993C3452.02,201.721 3580.45,180.583 3719.47,180.58C4011.66,180.583 4247.3,278.051 4426.39,472.986" style="fill:none;fill-rule:nonzero;stroke:black;stroke-width:1px;"/>
<path id="textCurve1" d="M564.216,1310.73C609.732,1475.4 770.154,1619.22 909.116,1635.49C993.881,1645.42 1152.78,1644.6 1262.96,1605.82C1479.72,1529.53 1626.78,1408.31 1802.89,1258.49" style="fill:none;fill-rule:nonzero;stroke:rgb(177,0,52);stroke-width:1px;"/>
</svg>
`)
let textCurve1 = draw.find("#textCurve1")[0]
let textPath = textCurve1.text("Forever").font({
size: textCurve1.height()
})
.attr({
startOffset: '50%',
'text-anchor': 'middle'
})
.fill({
opacity: 0
}).stroke({
color: "#000",
width: 1
})
红线是目标路径。文本需要遵循路径。
如您所见,文本曲线是正确的,但在 y 轴上的位置太低了。
我不确定如何解决这个问题,因为机会不多。我尝试了像 dominant-baseline 和 baseline-alignment 这样的属性,但没有任何效果
最佳答案
您可以使用带有 dx 属性的 tspan 来向上或向下移动特定文本。
const text = draw.text((text) => {
text.tspan('Some Text').dx(10)
}).path(textCurve1)
关于javascript - SVG.js TextPath 未与路径对齐(垂直),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63694567/
我在将 TextPath 元素与 svgwrite 库一起使用时遇到问题。我遵循文档 https://pythonhosted.org/svgwrite/classes/text.html#textp
我想沿着我的 SVG 路径对齐文本,但是,SVG 似乎不想将其与所有字母的正确旋转线上方对齐: 如何将文本对齐到曲线上方,以便其可读,而不是像上图所示? 我使用Snap.SVG库来进行 SVG 操作,
下面是 SVG 代码,将路径上的文本倒置显示。请帮助展示如何正确显示它。 Some Text→ 最
默认情况下,SVG 以逆时针方式围绕路径环绕文本。文本的天花板粘在路径上。如何将方向更改为顺时针,使文本的底部贴在圆周上而不是天花板上? .textspace { letter-spacing: 5p
我正在尝试根据我发现的一些示例制作一个动画旭日图,它可以缩放和更改数据表示形式:Vasco , Visual Cinnamon , David Richard等等 我无法让动画部分正常工作。弧正在更新
我正在尝试使用 svg.js 将文本放置到路径上 这是我的 fiddle : https://jsfiddle.net/Byteschmiede/ytz67egn/1/ var draw = SVG(
我在这里遇到了一个大问题。我需要翻转 180 度的 svg 元素的 textPath 标记中有一些文本。我已经使用了所有适用于 css 的方法,但绝对没有用。谁能帮我翻转元素内的文本。 functio
我在我的项目中使用SVG,并且希望在textpath元素上使用toggleClass与jQuery点击。 所以我在想: $("text#names > textpath").click(functio
对于 svg.js我写了一个添加 textPath 功能的小插件。该插件非常简洁: // textpath plugin SVG.TextPath = function() { this.co
我正在将 SVG 图形导出(使用 d3.js 库)到 PNG。问题是标签 textPath。导出为 PNG 时,文本不会出现。有谁知道这个问题是否有解决方案? 我用来进行转换的代码是: var svg
如何使路径 ( see screenshot) 上的文本扩展,使其跟随整个 textPath? 我试过使用 method attribute value stretch 但它没有像我预期的那样工作 -
有没有办法使用 SnapSVG 来使用文本路径?我尝试使用 textPath 作为属性,但它似乎没有在文本节点中添加 textpath 元素。 var txtpth = s.path("M70 70
我会将箭头放在路径的不同区域。实际上我正在使用 textPath。 textPath 的问题在于它与路径相关联,我无法在它们之间放置元素(例如路径上方但箭头下方的圆圈)。此外,我仅限于文本字符来绘制箭
这是我想要实现的目标的图像。 我有一些沿着路径弯曲的文本。我想在文本的开头和/或结尾放置一个 SVG 图像。在此示例中,它是一条丝带。但是如何将功能区放置在文本的开头/结尾,并使其旋转与路径上的文本匹
我正在尝试通过内联 SVG 在图像上叠加曲线文本。它在 Chrome 中运行良好,但 iOS 和桌面上的 Safari 无法呈现文本。
我想动态创建一个textPath,所以我这样写: function makeSVG(tag, attrs) { var el = document.createElementNS('h
是否可以内联定义 textPath 的路径,而不是创建 def 并将其作为 xlink:href 作为属性引用? My text along a
我遇到与 SVG 相关的带圆圈文本的问题。我的目标是创建一条路径,让我可以在上面书写,但也可以让文本居中,同时仍然跟踪我的路径 - 从圆圈的顶部开始。 示例 That's what it looks
我有一个图表,其中使用 textPath 沿着其中一个路径编写了一些文本。但是,我的问题是:我需要文本位于文本路径的另一侧,即位于其下方。 下面是一个例子: 我需要此处的文本位于纯蓝色区域内。也就是说
我在使用 snap.svg 为文本设置动画时遇到问题。我正在围绕圆弧移动文本,从圆弧的左下角到其顶点。我使用标准 Snap.animate 功能及其内置 setter 函数。 当我为随机元素(例如我在
我是一名优秀的程序员,十分优秀!