0

您如何将 Velocity.js 与包含在 HTML 对象标记中的 SVG 图形一起使用(这实际上是使用复杂图形的方式)。

基本上,包括图形:

<body>
  <div id="graph">
    <object id="objSvg" type="image/svg+xml
       data="./diagram-arch-server-SRS-CH.svg"></object>

然后,以下方法不起作用:

$("#server-webserver-4266").velocity({ x: "+=200", y: "25%" });
$("#objSvg").find("#server-webserver-4266").velocity({ fillGreen: 255, strokeWidth: 2 });

我正在使用 Velocity.js v1.4.3 和 jQuery v3.1.1 最新版本。我已经广泛搜索了解决方案,Velocity 文档仅包含内联 SVG 的示例(蹩脚!)。

4

1 回答 1

0

因此,对于 Pointy 的观点(在上面的评论中),这是一个使用 Javascript 访问正确 SVG 元素,然后使用 jQuery 应用 Velocity.js 方法的解决方案:

// refer to the HTML in the original post, then the following script works!
myObj = document.getElementById("objSvg");
myContent = myObj.contentDocument;
myServer = myContent.getElementById("server-webserver-4266");
$(myServer).velocity({ x: "150", y: "-=75" });
$(myServer).velocity({ fillGreen: 255, strokeWidth: 2 });

谢谢尖头!

于 2017-03-06T22:04:20.610 回答