Chrome似乎没有<use>在内联svg中显示元素.以下是一个示例(下面的代码或在http://www.bobwyttenbach.com/chromeuse.html上查看):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chrome use-tag bug?</title>
</head>
<body>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="200px" height="200px" viewBox="0 0 200 200">
<defs>
<g id="test1">
<circle cx="100" cy="100" r="50" fill="red"/>
</g>
</defs>
<g>
<rect x="0.5" y="0.5" width="199" height="199" stroke="black" fill="none"/>
<use xlink:href="#test1" x="0" y="0"/>
</g>
</svg>
<p>Above is inline svg with a use tag; below is the same svg linked through an object tag. Below is correct.</p>
<object data="chromeuse.svg" width="200" height="200"></object>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
红色圆圈不会出现在内联svg中,但会在通过对象标记链接相同的svg时出现.Safari,Firefox,Opera和Internet …
我相信我在 Chrome 的 SVG 渲染中发现了一个错误,但是我想知道是否有任何解决方法。
用这样的代码:
<html>
<body>
<svg>
<path clip-path="url(#clip)" d="M 0,100 H 1000 V 100" style="stroke: #000; stroke-width: 2px"></path>
<defs>
<clipPath id="clip">
<rect width="400" height="400"></rect>
</clipPath>
</defs>
</svg>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
应该有一条 1000px 长的水平线 ( path) 被 400px × 400px 剪裁rect。
该线在 Firefox 和 Internet Explorer (10) 中可见并正确剪切,但在 Chrome 中完全不可见。只有当path完全水平或垂直时才会出现问题,如本例所示。
要求 的d属性path是 D3.js 可以生成的等效项。