【问题标题】:How to manipulate long style from inkscape如何从inkscape中操作长样式
【发布时间】:2017-09-27 11:37:46
【问题描述】:

我在 object 标记中放置一个 svg(Inkscape 图片),像这样

<div class='rbis-svg-row'>
   <div class='rbis-salta-svg'>
      <object id='svg1'  data='factory4-network-salta.svg' type='image/svg+xml' width='900px'>
    </object>
  </div>  
</div>

然后我可以访问 svg 中的元素

<script>
    document.getElementById("svg1").addEventListener("load", function() {
       var doc = this.getSVGDocument();
        var rect = doc.querySelector('#rectABC'); 
        // Id for an object is rectABC                                                                                               

        var theStyle = reg.getAttribute('style');

     });

</script>

但是!

样式挺长的

"color:#000000;cliprule:nonzero;display:inline;overflow:visible;\
 visibility:visible;opacity:0.58999999;isolation:auto;\
 mix-blend mode:normal;colorinterpolation:sRGB;\
 color-interpolationfilters:linearRGB;solid-color:#000000;\
 solid-opacity:1;fill:#fcaf3e;fill-opacity:1;fill-rule:nonzero;\
 stroke:#000000;stroke-width:3;stroke-linecap:round;\
 stroke-linejoin:miter;stroke-miterlimit:4;\
 stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;\
 marker:none;color-rendering:auto;image-rendering:auto;\
 shape-rendering:auto;text-rendering:auto;enable-background:accumulate"

有什么好的方法可以改变样式中的单个属性吗?或者我必须 提取字符串并操作字符串?

/gh

【问题讨论】:

    标签: javascript svg inkscape setattribute


    【解决方案1】:

    您可以使用与 HTML 相同的方法。

    element.style.fill = "red";
    

    style 对象中的样式属性并不总是与 XML 属性具有相同的名称。如果属性有连字符,则属性将采用驼峰命名法。例如,fill-opacity 属性可以更改为:

    element.style.fillOpacity = 1;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-15
      • 2020-03-19
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 2019-02-15
      • 2014-04-16
      • 1970-01-01
      相关资源
      最近更新 更多