简体   繁体   English

线性渐变网址无效

[英]URL to linear gradient doesn't work

I have the following nested html elements : 我有以下嵌套的html元素:

<div class="trend-line-chart">
   <div class="title"></div>
   <div class="chart">
      <div class="">
         <svg width="200" height="100">
            <g>
               <g>
                  <g>
                     <path></path>
                     <path></path>
                     <path></path>
                     <g>
                        <defs>
                           <lineargradient id="LineChartGradient" gradientTransform="rotate(90)">
                              <stop offset="10%" stop-color="#D6EBF3"></stop>
                              <stop offset="10%" stop-color="#D6EBF3"></stop>
                           </lineargradient>
                        </defs>
                        <polygon points="...." stroke="#8AB9E1" stroke-width="0" fill="url(/dashboard/renderer#LineChartGradient)" fill-opacity="0.5"></polygon>
                     </g>
                  </g>
               </g>
            </g>
         </svg>
      </div>
   </div>
</div>

This component is within a larger html file with lots of other components. 此组件在包含许多其他组件的较大html文件中。

At first the fill gradient didn't work until I added /dashboard/renderer to its URL path (which you can see in the code above) . 最初,填充渐变直到我将/dashboard/renderer添加到其URL路径(您可以在上面的代码中看到)后才起作用。 Now , once again it's not working. 现在,再次无法正常工作。 As we are developing a dashboard , we move pages to different paths. 在开发仪表板时,我们将页面移动到不同的路径。 And I'm sure the reason of not showing up is the the url . 而且我敢肯定,没有出现的原因是url Any idea on how to refer to the fill gradient locally ? 关于如何在本地引用填充梯度的任何想法吗? So regardless of the path it always works. 因此,无论采用哪种方式,它始终有效。

Does you HTML header have a <base> element? 您的HTML标头是否包含<base>元素? If so, it will interfere with how the browser interprets gradient URLs. 如果是这样,它将干扰浏览器解释渐变URL的方式。

If you need to keep the <base> element, then the solution is to use an absolute URL (as you seem to have discovered). 如果您需要保留<base>元素,那么解决方案是使用绝对URL(您似乎已经发现)。

fill="url(/path/to/my/HTML/file#LineChartGradient)"

You say it has stopped working. 您说它已经停止工作了。 Has the URL of your page changed recently? 您页面的URL最近是否更改过?

SVG Gradients are defined in the document with a unique id attribute, and then referenced from another element as a URL. SVG渐变在文档中使用唯一的id属性定义,然后从另一个元素引用为URL。 Currently, our AngularJS code uses html base tag which stop the SVG Gradient from working. 当前,我们的AngularJS代码使用html base标记,这会使SVG渐变停止工作。 The reason is that the url is not relative to the current document anymore but they are computed relative to the specified separate URI. 原因是该URL不再相对于当前文档,而是相对于指定的单独URI计算的。

It looks like that there's a fix for this bug in AngularJS : https://github.com/angular/angular.js/issues/8934#issuecomment-56568466 看起来AngularJS中有此错误的修复程序: https : //github.com/angular/angular.js/issues/8934#issuecomment-56568466

References: 参考文献:

[1] SVG Gradient turns black when there is a BASE tag in HTML page? [1] 当HTML页面中有BASE标签时,SVG渐变会变黑吗?

[2] Angular and SVG filters [2] 角度和SVG滤镜

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

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