在Raphael中使用`setAttribute`设置双边框

问题描述 投票:0回答:1

在此jsFiddle中,我有两个SVG矩形。第一个在SVG标签内,第二个用Raphael JS渲染。两个矩形均应使用双边框,但不相同。应该在Raphael JS中使用node.setAttribute来设置低级SVG属性,因此应该可以使用。这里缺少什么?

<svg height="100" width="100">
  <rect class="rect2" height="50" width="50" x='25' y='25' />
</svg>

<div id="the_canvas"></div>


.rect2 {
  fill: none;
  outline: 2px double black;
  outline-offset: 0;
}


var w = 100, h = 100;
var paper = Raphael("the_canvas", w, h); 

var rect = paper.rect(25,25,50,50);
rect.node.setAttribute('fill', 'none');
rect.node.setAttribute('outline','2px double black');
rect.node.setAttribute('outline-offset', 0);
javascript svg raphael
1个回答
0
投票

这不是Raphael问题,而是SVG的工作方式。

轮廓和轮廓偏移不是映射的SVG属性。即它们不映射到CSS属性。实际上,这两个CSS属性都不应该在SVG中做任何事情(在SVG规范中未提及)。

浏览器的存在主要是为了呈现HTML,有时当它们只在HTML中不起作用时,仅应在HTML中起作用的东西才渗入SVG。

© www.soinside.com 2019 - 2024. All rights reserved.