简体   繁体   English

使svg缩放到全屏大小

[英]Make svg scale to full screen size

Im trying to scale a svg to the full size of the browser window. 我试图将svg缩放到浏览器窗口的完整大小。 The svg object is inside a div with both height and width set to 100% I have tried playing with the viewBox inside the svg to no avail. svg对象在div中,高度和宽度都设置为100%我试过用svg里面的viewBox玩无济于事。

The screen Im using has a 1080p res. 我使用的屏幕具有1080p res。

    <div style="width:100%; height: 100%;">
      <object id="map" type="image/svg+xml" data="worldHigh.svg">Your browser does not support SVG</object>
    </div>

viewBox="0 0 1920 1000" viewBox =“0 0 1920 1000”

With these settings the svg displays with its normal size and does not scale to the size of the window. 使用这些设置,svg将以正常大小显示,并且不会缩放到窗口大小。

When I set the width and height in the svg I can get it to the size of the display yet then the coordinates of the paths is wrong and sending a div to that spot is not where it should be. 当我在svg中设置宽度和高度时,我可以将其设置为显示的大小,然后路径的坐标是错误的,并且发送div到该位置不是应该的位置。

I think you are misunderstanding how viewBox works. 我认为你误解了viewBox工作原理。 It should describe the dimensions of your SVG contents , not your screen . 它应该描述SVG内容的尺寸,而不是屏幕 The purpose of viewBox is to tell the browser the dimensions of the graphic content, so it knows how much it needs to scale it to fit the parent container. viewBox的目的是告诉浏览器图形内容的尺寸,因此它知道需要多少才能缩放它以适应父容器。

So you need to find the minX, minY, width and height of the map. 所以你需要找到地图的minX,minY,宽度和高度。 If it's the same file I found by Googling, then it looks like the correct viewBox is: viewBox="0 0 1010 666" . 如果它是我通过谷歌搜索找到的相同文件,那么看起来正确的viewBox是: viewBox="0 0 1010 666" Try that. 试试吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM