为什么此 SVG 图形在 IE9 和 10(预览版)中无法缩放?
根据 IE 网站 支持 SVG。根据这个答案什么是SVG(可缩放矢量)图形)支持的浏览器?
http://jsfiddle.net/jitendravyas/2UWNe/show/
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="100%" height="100%" viewBox="0 0 480 360"
xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="button_surface" gradientUnits="objectBoundingBox"
x1="1" x2="1" y1="0" y2="1">
<stop stop-color="#434343" offset="0"/>
<stop stop-color="#000000" offset="0.67"/>
</linearGradient>
<linearGradient id="virtual_light" gradientUnits="objectBoundingBox"
x1="0" x2="0" y1="0" y2="1">
<stop stop-color="#EEEEEE" offset="0" stop-opacity="1"/>
<stop stop-color="#EEEEEE" offset="0.4" stop-opacity="0"/>
</linearGradient>
</defs>
<!-- button content -->
<rect x="10" y="10" rx="15" ry="15" width="150" height="80"
fill="url(#button_surface)" stroke="#363636"/>
<text x="30" y="55" fill="white"
font-family="Tahoma" font-size="20" font-weight="500">
SVG Button
</text>
<!-- vitual lighting effect -->
<rect x="12" y="12" rx="15" ry="15" width="146" height="76"
fill="url(#virtual_light)" stroke="#FFFFFF" stroke-opacity="0.4"/>
</svg>
According to IE website SVG is supported. And according to this answer too What are SVG (Scalable Vector Graphics) supported browsers?
http://jsfiddle.net/jitendravyas/2UWNe/show/
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="100%" height="100%" viewBox="0 0 480 360"
xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="button_surface" gradientUnits="objectBoundingBox"
x1="1" x2="1" y1="0" y2="1">
<stop stop-color="#434343" offset="0"/>
<stop stop-color="#000000" offset="0.67"/>
</linearGradient>
<linearGradient id="virtual_light" gradientUnits="objectBoundingBox"
x1="0" x2="0" y1="0" y2="1">
<stop stop-color="#EEEEEE" offset="0" stop-opacity="1"/>
<stop stop-color="#EEEEEE" offset="0.4" stop-opacity="0"/>
</linearGradient>
</defs>
<!-- button content -->
<rect x="10" y="10" rx="15" ry="15" width="150" height="80"
fill="url(#button_surface)" stroke="#363636"/>
<text x="30" y="55" fill="white"
font-family="Tahoma" font-size="20" font-weight="500">
SVG Button
</text>
<!-- vitual lighting effect -->
<rect x="12" y="12" rx="15" ry="15" width="146" height="76"
fill="url(#virtual_light)" stroke="#FFFFFF" stroke-opacity="0.4"/>
</svg>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
IE 似乎对缺失的
preserveAspectRatio
处理不当属性。您可以通过添加preserveAspectRatio="xMinYMin slice"
来使其在 IE 中缩放,如下所示:http://jsfiddle.net/2UWNe/4/show
但是,IE 显示的不是正确的行为,因此此更改会导致其他浏览器的行为与 IE 不同。 (然而,微软相信他们支持
preserveAspectRatio
.)我还没有深入研究你的单位或内容边界框。你真正想达到什么效果?
IE seems to be mishandling the missing
preserveAspectRatio
attribute. You can get it to scale in IE by addingpreserveAspectRatio="xMinYMin slice"
as seen here:http://jsfiddle.net/2UWNe/4/show
However, what IE is showing is not the correct behavior, and thus this change causes other browsers to behave differently than IE. (Microsoft, however, believes that they support
preserveAspectRatio
.)I haven't looked deeply at your units or content bounding boxes. What effect are you really trying to achieve?
SVG 的缩放方式与 JPG、PNG 和 GIF 等具有明确定义尺寸的光栅图像不同。
您将需要采取一些技巧来保证跨浏览器的相同显示。
试试这个:
查看演示
了解更多
SVGs don't scale the same way as raster images like JPG, PNG, and GIF which have a clearly defined size.
You will need to resort to hacks to guarantee same display across browsers.
Try this:
See Demo
Learn more
问题是您使用百分比来表示高度和宽度,如此处所述(http://www.seowarp.com/blog/2011 /06/svg-scaling-problems-in-ie9-and-other-browsers/)。
更改为
width=480
和height=360
应该没问题。The problem is that you are using percentages for height and width, as explained here (http://www.seowarp.com/blog/2011/06/svg-scaling-problems-in-ie9-and-other-browsers/).
Change to
width=480
andheight=360
and you should be fine.另一种选择是使用视口单位。这样你的 SVG 将根据窗口的大小进行缩放:
https://jsfiddle.net/orikon/qy43fb0p/
Another option is to use viewport units. This way your SVG will scale according to the size of the window:
https://jsfiddle.net/orikon/qy43fb0p/