我有两个svg在我的html中,我想把它们分组,所以最后我有一个包含两个svg部分的body。我该怎么做呢?
工作畜栏:https://codepen.io/m42444/pen/eYVEbOq
目前我正在渲染两个svg,就像下面的代码:
const vertexSets = [],
$("#svgOne")
.find("path")
.each(function (i, path) {
var svgOne = Bodies.fromVertices(
percentX(80),
percentY(30),
Matter.Vertices.scale(
Svg.pathToVertices(path, 10),
window.innerWidth / 2000,
window.innerWidth / 2000,
),
{
render: {
fillStyle: #F9420B,
strokeStyle: #F9420B,
lineWidth: 1,
},
},
true,
);
vertexSets.push(svgOne);
});
$("#svgTwo")
.find("path")
.each(function (i, path) {
var svgTwo = Bodies.fromVertices(
percentX(80),
percentY(30),
Matter.Vertices.scale(
Svg.pathToVertices(path, 10),
window.innerWidth / 2000,
window.innerWidth / 2000,
),
{
render: {
fillStyle: #F9420B,
strokeStyle: #F9420B,
lineWidth: 1,
},
},
true,
);
vertexSets.push(svgTwo);
});
World.add(engine.world, vertexSets);
<svg id="svgOne" style="position:absolute; width: 0; height: 0" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" xml:space="preserve">
<g>
<path class="e" d="M93.87,11.03S-16.33,82.23,2.07,171.13s105.8,179.6,174.3,238c68.5,58.4,109.1,86.2,125.2,179.6s7.3,128.4,53.8,100.2,56.9,2.4,74.5-29.7c17.5-32.2-64.7-117.3-78.4-164.2-13.7-46.8,12-169.1-18.3-328.1C302.87,8.03,164.07-19.67,93.87,11.03Z"/>
</g>
</svg>
<svg id="svgTwo" style="position:absolute; width: 0; height: 0" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" xml:space="preserve">
<g>
<path d="M116.37,127.73c9.7-4,18.8-7.8,29.1-12.1-2.9-7.1-5.6-14-8.7-20.8-1.4-3.1-2.2-5.6,1.9-6.9,3.2-1,6.6-3.4,8.8,1.9,7.5,18.5,15.3,37,22.8,55.5,2.1,5.1-2.8,11.6-8.3,11.2-1.3-.1-3.1-2-3.7-3.4-2.5-6.2-4.7-12.5-7.1-18.7-.9-2.5-2-4.9-3.2-7.8-9.3,3.8-18.2,7.6-28.2,11.7,3.1,7.4,6.1,15,9.4,22.6,2.5,5.7-1.1,11.2-7.5,10.7-1.3-.1-3-2-3.6-3.4-7.8-18.6-15.4-37.4-23.2-56-1.5-3.7-1.4-6.5,2.7-8.1,3.9-1.6,7.1-1.7,9.2,2.9,2.9,6.8,6.2,13.5,9.6,20.7Z"/>
</g>
</svg>
1条答案
按热度按时间cqoc49vn1#
你是指这样的东西吗?(如下面的代码)
svg图像看起来与网页上的不一样,但我认为这与
Matter.Svg.pathToVertices
函数有关,因为documentation声明:* "...请注意,此函数不保证支持复杂路径(例如,带有孔的路径)。..."*