简体   繁体   中英

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. I want to scale it in the x and y axis but it is not working. 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. 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. You can do this by opening steve.svg in a text editor and adding width="100%" height="100%" to the <svg></svg> tags

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM