[英]How to scale SVG element to fit parent element using JQuery
Simple code below: 下面的简单代码:
I am trying to copy a svg element in the document and append it to another element. 我正在尝试在文档中复制svg元素并将其附加到另一个元素。
But I need to resize the svg to fit the new element only using JS. 但是我只需要使用JS来调整svg的大小以适合新元素 。
const $SVG = $('svg').clone();
//Resize SVG
$('li').append($SVG);
Try using CSS: 尝试使用CSS:
li{
width: [some dimension in px];
height: [some dimension in px];
}
li svg{
display:inline-block;
width:100%;
height:100%;
}
I don't know about jQuery but you could take a look at a script i wrote that helps scale a svg path with it's parent element by adding a simple attribute, data-rel-d
. 我不了解jQuery,但是您可以看一下我写的脚本,该脚本通过添加简单属性
data-rel-d
来帮助缩放带有其父元素的svg路径。 Check it out here: https://github.com/mrdivinemaniac/RelativePath.js 在这里查看: https : //github.com/mrdivinemaniac/RelativePath.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.