简体   繁体   中英

resize only the image inside svg

I have the following code:

<svg id="svg1" width="120%" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns="http://www.w3.org/2000/svg" style="height: 580px;">
<g id="g1" transform="scale(1)">
<image id="backgroundImg" x="0px" y="0px" width="799px" height="513px"
xlink:href="../FileOutput.aspx?FileID=34">
<line name="grid" x1="0" y1="4995" x2="5000" y2="4995" stroke="#BBBBBB" stroke-width="0.5">

I want to create a slider that can resize just the image and not any other elements inside the svg. I am new to svg and have no idea if I am asking a proper question. But still is this possible? If it is then how?

You can simply access the <image> node's attributes via JavaScript (using .setAttribute() ):

var image = document.getElementById('backgroundImg');
image.setAttribute('width', '10px');
image.setAttribute('height', '10px');

See this fiddle

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