Notes
There are two separate SVG elements on the page:
Each SVG lies within a div, named after its purpose (div#main and div#mini)
The main SVG is nested within another SVG (svg.aperture)
Use CSS to size the SVGs appropriately on the page
About widths and heights:
width and height attributessvg#butterflysvg.aperture), so that the viewport of that main svg is defined.svg.aperture constant on the page, while its viewBox string changes (this method uses that viewBox string to zoom and translate).flex-grow: 3 for the main SVG and flex-grow: 1 for the minimap will ensure that the main is 3 times as large as the minimap on screen. The two SVGs might still have identical width and height attributes.viewBox attribute the magnifying SVG (svg.aperture)viewBox is the string of the form "<min-x> <min-y> width height" so we get "0 0 400 250"viewBox is also applied to the minimap SVGsvg.aperture is due to its preserveAspectRatio attribute being nonesvg#butterfly (which is contained within svg.aperture) will stretch to fit its parent (svg.aperture), regardless of width:height ratioRendering the SVG twice
id attribute. This is required for this technique to work.<use xlink:href="#butterfly">Zoom behavior
svg.aperture and the minimap SVG.x, y and k values__zoom property on the minimap.__zoom property for the main and minimap SVGs__zoom property on each, we ensure that both SVGs have the same zoom values at all times.Links
Built with blockbuilder.org
forked from seemantk‘s block: “Minimap” Zoom/Pan with viewBox