SVG resizing in IE9

青春壹個敷衍的年華 提交于 2019-12-05 08:48:10

I haven't tested this in IE yet but if you're looking to use 100% width and height the I assume you either want it to be 'fullscreen' or to fit within a container. Since you also mentioned that it scales correctly when...

setting the width and height of the containing div will make the image larger, but only with fixed pixels

...then you can use JS for this. With jQuery, for example, you can do the following:

$(window).resize(function()
{
    $('#outer').css({
        width: $(window).width() + 'px',
        height: $(window).height() + 'px'
    })
});

This is assuming that you want your #outer container to be the width and height of the window when the window is resized.

I know you've said you'd like to avoid setting the width and height, but that's the only way I've managed to get it to work, personally.

Though I did figure out that you only need to set the height, you can leave the width at 100%, so:

        var container = this.$('.container'),
            width = container.width(),
            scale = svg.width / width;

        container.height(parseInt(svg.height / scale, 10));

Where svg.width and svg.height are the values I know to be the original width and height of the SVG..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!