简体   繁体   English

Position 使用fabric.JS的一行中点的文本?

[英]Position text in the midpoint of a line using fabric.JS?

I am currently trying to position text in the middle of a line.我目前正在尝试将 position 文本放在一行中间。 I do know the equation - the two point's vector's averages - but they seem to appear in a different position.我确实知道这个方程——两点向量的平均值——但它们似乎出现在不同的 position 中。 I am using我在用

 texts[0].set({ text: value, left: (points[0] - points[2]) / 2, top: 345, textAlign: “center" });

Are the left and top the same as X and Y? left 和 top 是否与 X 和 Y 相同? Points of the line are calculated as the following:线的点计算如下:

points = [360 - (value.length * 80), 300, 300, 300]

Thank you!谢谢!

I was being an idiot, and found the problem: I was subtracting the point's X positions.我是个白痴,发现了问题:我正在减去该点的 X 位置。 This is why you shouldn't do 12 AM scripting, kids!这就是为什么你不应该在凌晨 12 点编写脚本的原因,孩子们!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM