【问题标题】:change length of svg line in DART更改 DART 中 svg 行的长度
【发布时间】:2023-03-29 18:26:01
【问题描述】:

我在 HTML 中有 SVG 行,想更改结束坐标。

 <svg  xmlns="http://www.w3.org/2000/svg" version="1.1" >   
   <line id="myline" x1="0" y1="0" x2="200" y2="200"
        style="stroke:rgb(255,0,0);stroke-width:2"/>  
 </svg>

在 Dart 代码中,我有以下内容:

LineElement line = query("#myline");

我需要将 x2 从 200 更改为 220,但我没有看到线的 x2 属性。 有可能吗?

【问题讨论】:

    标签: dart dart-html


    【解决方案1】:

    LineElement 确实具有 x2 属性,您可以在文档http://api.dartlang.org/docs/releases/latest/dart_svg/LineElement.html#x2 中看到。

    您可以通过以下任一方法设置 x2:

    line.attributes["x2"] = "220";
    line.$dom_setAttribute("x2", "220");
    

    【讨论】:

      【解决方案2】:

      我需要将 x2 从 200 更改为 220,但我没有看到线的 x2 属性。有可能吗?

      是的,很简单:

      LineElement line = query("#myline");
      line.attributes['x2'] = '220';
      

      attributes 属性可以在每个Element 中找到,包括LineElement

      【讨论】:

        猜你喜欢
        • 2023-02-10
        • 2012-06-11
        • 2023-04-06
        • 2022-08-19
        • 2022-11-01
        • 1970-01-01
        • 2021-03-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多