【问题标题】:How to style SVG with Dart?如何使用 Dart 设置 SVG 样式?
【发布时间】:2014-01-02 01:53:55
【问题描述】:

我正在尝试设置 SVGElement 的样式但失败了。这是我的代码:

import 'dart:html';
import 'dart:svg';

main(){
    document.querySelector('#path').style.fill='none';//javascript: working, Dart: not working
}

如何让它在 Dart 中工作?

【问题讨论】:

    标签: css svg dart dart-html


    【解决方案1】:

    DOM 元素的样式属性是“CssStyleDeclaration”(https://api.dartlang.org/docs/channels/stable/latest/dart_html/CssStyleDeclaration.html)。这个类封装了css的所有属性(据我所知)。它不构成“填充”属性,因此您无法设置它。我建议你使用

    String className
    

    CssClassSet classes
    

    用于设置定义填充样式的 CSS 类的属性。

    var element = querySelector('#path');
    element.classes.add('yourSvgClass');
    

    【讨论】:

      【解决方案2】:

      您可以设置 CssStyleDeclaration 的填充属性,即使它没有类似的适当属性

      document.querySelector('#circle').style.setProperty('fill', 'none');
      

      如果您将属性名称作为字符串参数获取,则此样式非常有用。

      【讨论】:

        猜你喜欢
        • 2016-07-30
        • 1970-01-01
        • 2013-08-28
        • 2021-07-04
        • 1970-01-01
        • 2015-09-16
        相关资源
        最近更新 更多