4
我有下面的代碼片斷:繪圖SVG使用Javascript
draw: function drawFn ($dial) {
var width = $dial.width(),
height = $dial.height(),
$svg = $('<svg />').attr({
"width": width,
"height": height
}),
circle = $('<circle />').attr({
"cx": 0,
"cy": 0,
"r": width/2,
"fill": "red"
});
$svg.append(circle);
$dial.append($svg);
}
$dial
是一個jQuery包裹<div>
元件具有寬度和高度。
<svg>
和<circle>
元素都附加到<div>
,但它們沒有可見大小。我錯過了什麼?
小提琴這裏:http://jsfiddle.net/alexcoady/pLvAw/2/
,你需要添加的jQuery – dievardump
哈哈,你打敗了我。現在增加:) – Alex
這可能是原因http://stackoverflow.com/questions/3642035/jquerys-append-not-working-with-svg-element – svillamayor