Height and width SVG

Asked

Viewed 76 times

0

I have an SVG element and I want its height and width to fit according to the resolution. For this I will get in javascript through screen.width. Now I wanted to insert this obtained value into the svg tag. It is possible to do this?

<script>
 var window_width = screen.width;
 var window_height = screen.height;
</script>
<svg width="<script type='text/javascript'>screen.width</script>" height="500">

  • http://stackoverflow.com/questions/10973339/modifying-svg-attributes-with-javascript-has-no-effect

1 answer

1


You can do so directly in js, follow below modification of your code:

<svg id="xyz">

<script>
 var window_width = screen.width;
 var window_height = screen.height;

 var mySvg = document.getElementById("xyz");
 mySvg.style.width=window.width;
 mysvg.style.height=window_height;

</script>

Remembering that the script should come below the tag "svg"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.