在Scala.js中,修改svg.Stylable.style

时间:2018-07-05 11:09:53

标签: svg scala.js

使用Scala.js,我创建了一些SVG元素,例如TextLineRect,现在我正尝试使用如下代码设置样式属性,其中element的类型为svg.Stylable

element.style.fillOpacity = "0.0"
element.style.stroke = "yellow"
element.style.strokeWidth = "2"

我尝试了上述代码的不同变体,但是所需的样式并未实现,并且当我在浏览器中检查元素时,样式属性为空的String(“”)。我可以毫无问题地设置其他属性(例如xywidthheight)。

如何设置样式?谢谢!

1 个答案:

答案 0 :(得分:0)

对于Scala.js中的SVG药物,我通常使用d3库(scala.js外观:https://github.com/spaced/scala-js-d3)。

然后您可以使用:

d3.select("#mySvgElement").attr("style", "stroke:yellow; stroke-width:2") // etc.

*编辑:mySvgElement是我要更改其样式的元素的ID。您还可以使用其他类型的selectors