[英]How to scale svg in x and y axis from a object tag?
In my html file, I have a svg loaded through a object tag. 在我的html文件中,我有一个通过对象标记加载的svg。 I want to scale it in the x and y axis but it is not working.
我想在x和y轴上缩放它,但是它不起作用。 Does anyone know how to do it?
有人知道怎么做吗?
Thanks 谢谢
<!DOCTYPE html>
<html>
<head>
<title>Animate</title>
<style>
</style>
</head>
<body>
<object data="images/steve/steve.svg" type="image/svg+xml" id="steve" width="100%" height="100%"></object>
<script>
var steve = document.getElementById("steve");
steve.addEventListener("load", function() {
var svgDoc = steve.contentDocument;
//steve.setAttribute('transform','scale(1.0 2.0)'); // this does not work
},false);
</script>
</body>
</html>
put the svg element in a div and scale that instead. 将svg元素放入div并进行缩放。 Also, make sure you set width and height to 100% on the svg element itself within "steve.svg" so that it scales with the element.
另外,请确保在“ steve.svg”中将svg元素本身的宽度和高度设置为100%,以使其随元素缩放。 You can do this by opening steve.svg in a text editor and adding
width="100%" height="100%"
to the <svg></svg>
tags 您可以通过在文本编辑器中打开steve.svg并在
<svg></svg>
标记中添加width="100%" height="100%"
来完成此操作
<div id="steve-container">
<object data="images/steve/steve.svg" type="image/svg+xml" id="steve" width="100%" height="100%"></object>
</div>
then just set the css style on steve-container to the desired size 然后只需在steve-container上将css样式设置为所需的大小
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.