简体   繁体   English

Fabric JS-在两点之间画一条线的百分比

[英]Fabric JS - draw a percent of a line between two points

So I can draw a line in Fabric JS; 所以我可以在Fabric JS中画一条线;

var line = new fabric.Line([x1, y1, x2, y2], {
    stroke: 'red',
    strokeWidth: 0.9
});
canvas.add(line);

However I only want to draw perhaps half of the line or 20% of the line, so it needs to go from x1,y1 but only be drawn 20% of the way towards x2,y2 但是我只想画线的一半或那条线的20%,所以它需要从x1,y1但只画到x2,y2 20%。

The docs don't seem to offer this functionality, is there a way to do this in Fabric already? 这些文档似乎没有提供此功能,Fabric中已经有办法做到这一点吗? Or any anyone help with another solution? 还是有人帮助其他解决方案?

Ye Olde Maths approach: Ye Olde Maths方法:

var line = new fabric.Line([x1, y1, x1 + ((x2 - x1) / 5), y1 + ((y2 - y1) / 5)]

Should get you about 20% there on a straight line. 应该可以使您直线上升约20%。

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

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