简体   繁体   中英

How to change viewBox to center an element in svg

I have a svg map which contains a bunch of circles, on click on a circle I want to make the circle the center of the canvas. I am using RaphaelJS to work with svg.

I have tried paper.setViewBox(width / 2 - cx, height / 2 - cy, width, height, true) , where cx and xy are the coordinates of the selected circle in my svg file, but it doesn't work.

Your calculations look wrong to me. I would expect it to be:

paper.setViewBox(cx - width / 2, cy - height / 2, width, height, true)

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