SVG pattern not working in Safari

大城市里の小女人 提交于 2019-12-23 11:58:41

问题


I am trying to make a grid-like pattern using SVG. I am seeing really weird behavior with <router-outlet>, when I use this code via route (say localhost/test) then it fails to load pattern in Safari but using the selector of the component it works perfectly.

<defs>
     <pattern id="pattern" width="10" height="10">
         <path d="M10,0 L10,10 L0,10" fill="none" stroke="#E9E9E9" stroke-width="1"/>
     </pattern>
</defs>

<rect id="test" x="10" y="10" width="250" height="250" style="fill: url('#pattern');"/>

This works great in Chrome but it is showing black rect in safari. Also if I fill it with color then also it works in both browsers, but pattern is not working in Safari. Any suggestion on why such problem is occurring?


回答1:


Safari needs complete path, unlike chrome. It cannot take relative path hence 'url(' + location.protocol + '//' + location.host + location.pathname + '#pattern)' will work both on safari and chrome



来源:https://stackoverflow.com/questions/49409414/svg-pattern-not-working-in-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!