2015-03-25 125 views
5

我想弄清楚爲什麼這段代碼在Firefox中不起作用。它應該創建水平路徑,但我無法在Firefox中看到它們。 Chrome和IE正確顯示它們。可能是什麼問題?動態創建的SVG不能在Firefox中工作,但在Chrome中工作

https://jsfiddle.net/7a6qm371/

<div> 
<svg width="100%" height="500" id="svgBottomWall"> 
    <g style="stroke: aqua; fill: none;" id="svgBottomWallGridGroup"></g> 
</svg> 

$(document).ready(function() { 

var svgBottomWall = document.getElementById("svgBottomWall"); 
var rect = svgBottomWall.getBoundingClientRect(); 
var svgW = rect.width; 



function createHorizontalLine(w, d) { 
    var nline = document.createElementNS("http://www.w3.org/2000/svg", "path"); 
    nline.setAttribute("d", "M 0 " + d + ", L " + w + " " + d); 
    nline.setAttribute("stroke-width", 1); 
    nline.setAttribute("stroke", "#ffffff"); 
    document.getElementById("svgBottomWallGridGroup").appendChild(nline); 
} 
for (var i = 0; i <= svgW; i = i + 100) { 
    createHorizontalLine(svgW, i); 
} 
}); 
+0

似乎是'svgBottomWall.clientWidth',就像你在你的小提琴中在Firefox中返回'0'。我嘗試在循環中使用固定值,但它仍然不起作用,所以這只是您的一個問題。 – Phil 2015-03-26 01:13:21

回答

相關問題