【发布时间】:2018-02-05 14:34:51
【问题描述】:
我正在编写一个显示图表并显示依赖关系的简单网页。我发现path 元素在svg 中的呈现方式出现了意外行为。
这是示例的完整 HTML:
<html>
<body>
<svg id="svgConnections" xmlns="http://www.w3.org/2000/svg" style="width: 300px; height: 120px">
<defs>
<linearGradient id="grad1" >
<stop offset="0%" style="stop-color:yellow;stop-opacity:1" />
<stop offset="100%" style="stop-color:red;stop-opacity:1" />
</linearGradient>
</defs>
<path d="M40,40 L100,100 Z" stroke="url(#grad1)" strokeWidth="1px" />
<path d="M200,100 L140,40 Z" stroke="url(#grad1)" strokeWidth="1px" />
</svg>
</body>
</html>
同样的例子在https://jsfiddle.net/4fLjm0e2/
让我烦恼的是,从左上角到右下角的第一行看起来与第二行“相反”:从右下角到左上角。
如何让路径始终以黄色开始并以红色结束?
【问题讨论】:
-
我刚刚阅读了文档,但没有找到任何可以轻松帮助您的内容。一种解决方案是根据线的方向设置
x1、x2、y1、y1(<linearGraient>的属性),但我希望有一个简单的解决方案。
标签: javascript html dom svg