I want to change the attributes on an svg element in an html page.
svgElement.setAttribute("width", `${width_}`); //instruction 1
svgElement.setAttribute("height", `${height_}`); //instruction 2
svgElement.setAttribute("viewBox",`${x} ${y} ${width_} ${height_}`); // instruction 3
width_ and height_ are new values, different from the pre existing attribute values.
"instruction 1" causes a horizontal zoom.
"instruction 2" causes a vertical zoom.
"instruction 3" zooms everything back to how it was before, as if there had been no zooming at all.
Is it possible to avoid this effect ?
I was looking into the possibility of setting multiple attributes in one single transaction, but it does not seem possible (correct me if I am wrong).
If changing the
<svg>element's size and viewBox at almost the same time leads to flickering, consider leaving the<svg>element's size and viewBox unchanged and changing only the size of<div>element surrounding the<svg>element and<clipPath>element controlling the visible size of the<svg>contents.But in this example at least, I cannot really spot a difference between the two approaches.