svg-pan-zoom icon indicating copy to clipboard operation
svg-pan-zoom copied to clipboard

Re-positioning controls

Open dmb0058 opened this issue 2 years ago • 1 comments

Hi!

Amazing work - thank you so much. A small question: how to re-position the zoom controls to the top-left ?

I found this https://github.com/bumbu/svg-pan-zoom/issues/312#issuecomment-418888511 and I think the custom controls approach is what I need, but the link to the example is broken.

Thanks for any help,

David

dmb0058 avatar Nov 29 '22 14:11 dmb0058

This works for me:

            // reposition the controls
            const controls = document.querySelector('g[id="svg-pan-zoom-controls"]');
            //get height and width of svg
            const svgHeight = svg.getBoundingClientRect().height;
            const svgWidth = svg.getBoundingClientRect().width;
            //set the controls to be 15% from the top of the svg and 100px from the right
            controls.setAttribute('transform', 'translate(' + (svgWidth - 100) + ', ' + (svgHeight * 0.15) + ')');

I also wrap this in a function that fires on window resize.

lancedouglas1 avatar May 21 '23 17:05 lancedouglas1