【发布时间】:2015-09-07 07:12:09
【问题描述】:
我正在使用以下内容来设置响应式 SVG
outerHeight = 400;
outerWidth = 600;
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = outerWidth - margin.left - margin.right,
height = outerHeight - margin.top - margin.bottom;
var svg = d3.select("div#simulation-1")
.append("svg")
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 "+outerWidth+" "+outerHeight)
.attr("class","svg");
这在 Chrome 中完美运行。然而,在 IE11 和 Firefox 中,整个图表按比例缩小(轴和字体很小),viewBox 的值为
viewbox="0 0 1936 1056"
由于某种原因,它不接受指定的高度和 with。但是它仍然是响应式的。
包含的小提琴:https://jsfiddle.net/4p73n364/
有什么想法吗? 问候, 让
【问题讨论】:
-
你能准备一个(小)小提琴来展示效果吗?
-
我可以看到问题,但我无法自行解决。但是,tympanus.net/codrops/2014/08/19/making-svgs-responsive-with-css 提出的解决方案似乎可行。示例可见于tympanus.net/Tutorials/ResponsiveSVGs/index4.html
-
看起来问题是外部宽度、外部高度以及轴的宽度和高度使用全局变量。似乎 Chrome 对待全局变量的方式与其他浏览器不同,可能是一些命名空间问题
标签: internet-explorer firefox svg d3.js