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

标签 javascript svg raphael

在此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);

最佳答案

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

outline 和outline-offset 不是映射的SVG 属性。 IE。它们不映射到 CSS 属性。事实上,这些 CSS 属性都不应该在 SVG 中真正执行任何操作(SVG 规范中没有提及它们)。

浏览器的存在主要是为了渲染 HTML,有时一些只在 HTML 中起作用的东西会渗入到 SVG 中,而实际上它们在 SVG 中应该不起作用。

关于javascript - 在 Raphael 中使用 `setAttribute` 设置双边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59124787/

相关文章:

javascript - 将 ProfileImage 添加到照片 Controller

javascript - 基础下拉菜单(使用 Plunker)

java - 如何将显示 SVG 的 WebView 缩放到固定像素高度?

html - Raphael js文本定位: centering text in a circle

javascript - () => {} 在 gulpfile.js 中是什么意思

javascript - 使 Intro.js 工具提示响应

javascript - 使用 javascript 缩放选定的 svg 元素

pdf - FPDF 中的 SVG 图形

javascript - 如何在 <div> 标签中添加 raphaeljs 对象

javascript - 在 DOM 中获取 raphael id 属性