简体   繁体   English

Javascript 生成的 svg 与 styles 在浏览器中可以正常工作,但在浏览器之外不能正常工作

[英]Javascript generated svg with styles works fine in browsers but not outside browser

I have this javscript generated svg我有这个 javscript 生成的 svg

 <svg width="240" height="320" viewBox="0 0 240 320" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg> <path d="M228 319.5H12C5.64873 319.5 0.5 314.351 0.5 308V12C0.5 5.64873 5.64873 0.5 12 0.5H159.175C159.571 0.5 159.952 0.656748 160.233 0.936021L239.057 79.2681C239.341 79.5497 239.5 79.9326 239.5 80.3321V308C239.5 314.351 234.351 319.5 228 319.5Z" fill="#FFF9F2" stroke="#FFC681"/> </svg> <svg style="filter: invert(1); mix-blend-mode: color-burn"> <path fill-rule="evenodd" clip-rule="evenodd" d="M99 117C96.7909 117 95 118.791 95 121V148.939C94.3386 148.979 93.6717 149 93 149C75.3269 149 61 134.673 61 117C61 99.3269 75.3269 85 93 85C110.673 85 125 99.3269 125 117H99ZM125 117H155C157.209 117 159 118.791 159 121V177C159 179.209 157.209 181 155 181H99C96.7909 181 95 179.209 95 177V148.939C111.741 147.906 125 134.001 125 117Z" fill="#FFC681"/> </svg> </svg>

this is the desired result in any program.这是任何程序的期望结果。

在此处输入图像描述

it has some styling ( style="filter: invert(1); mix-blend-mode: burn" ) and inside the browser this works as expected, but these styles are totally ignored if opening it in anyother program.它有一些样式( style="filter: invert(1); mix-blend-mode: burn" )并且在浏览器内部按预期工作,但是如果在任何其他程序中打开它,这些 styles 将被完全忽略。

在此处输入图像描述

what can I do in order to include the styling for the svg outside the browser?我该怎么做才能在浏览器外部包含 svg 的样式?

You might be able to replace the CSS filter and the blend mode with an equivalent SVG <filter> , as described here .您也许可以用等效的 SVG <filter>替换 CSS 过滤器和混合模式,如此所述。 With librsvg v2.50, which is what Ubuntu uses for rendering, the following does work, same as Chrome, but it fails in Firefox.使用librsvg v2.50,这是 Ubuntu 用于渲染的内容,以下工作与 Chrome 相同,但在 Firefox 中失败。 For Windows, you'll have to hope.对于 Windows,您必须抱有希望。 mode="color-burn" is an attribute value that was only introduced with SVG 2. Some renderers might not support it. mode="color-burn"是仅在 SVG 2 中引入的属性值。某些渲染器可能不支持它。

 <svg width="240" height="320" viewBox="0 0 240 320" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <filter id="inverse-burn" color-interpolation-filters="sRGB"> <feComponentTransfer result="invert"> <feFuncR type="table" tableValues="1 0"/> <feFuncG type="table" tableValues="1 0"/> <feFuncB type="table" tableValues="1 0"/> </feComponentTransfer> <feImage xlink:href="#background" result="base" x="0" y="0" width="240" height="320" /> <feBlend in="invert" in2="base" mode="color-burn" /> </filter> <path id="background" d="M228 319.5H12C5.64873 319.5 0.5 314.351 0.5 308V12C0.5 5.64873 5.64873 0.5 12 0.5H159.175C159.571 0.5 159.952 0.656748 160.233 0.936021L239.057 79.2681C239.341 79.5497 239.5 79.9326 239.5 80.3321V308C239.5 314.351 234.351 319.5 228 319.5Z" fill="#FFF9F2" stroke="#FFC681"/> <g style="filter:url(#inverse-burn)"> <path fill-rule="evenodd" d="M99 117C96.7909 117 95 118.791 95 121V148.939C94.3386 148.979 93.6717 149 93 149C75.3269 149 61 134.673 61 117C61 99.3269 75.3269 85 93 85C110.673 85 125 99.3269 125 117H99ZM125 117H155C157.209 117 159 118.791 159 121V177C159 179.209 157.209 181 155 181H99C96.7909 181 95 179.209 95 177V148.939C111.741 147.906 125 134.001 125 117Z" fill="#FFC681"/> </g> </svg>

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

相关问题 JavaScript在Firefox以外的任何浏览器中都能正常工作吗? - JavaScript works fine in any browser but Firefox? 我的Javascript代码在IE中不起作用,但在其他浏览器中也可以正常工作 - My Javascript code does not work in IE but works fine in other browsers 为什么 javascript 在 RN webview 中不起作用,但桌面浏览器工作正常? - Why does javascript not work in RN webview but desktop browser works fine? JavaScript无法在ie11中正常运行,但在所有其他浏览器中都能正常运行 - JavaScript not functioning as expected in ie11 but works fine in all other browsers 通过JavaScript设置其他样式效果很好,但是如何设置字体系列? - Setting other styles via JavaScript works fine, but how can I set font-family? 该网站可以在除Firefox之外的其他浏览器上正常运行 - Site works fine on other browsers except for Firefox React应用正常运行,但不能在移动浏览器上运行 - React app works fine but not on mobile browsers 从javascript编辑SVG样式 - Editing SVG styles from javascript 使用JavaScript生成的样式保存HTML - Save HTML with javascript generated styles 在Firefox中导出javascript生成的csv仅导出第一行,在chrome中可以正常工作 - Exporting javascript generated csv in Firefox only exports first line, works fine in chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM