动态创建的“圆圈”不可见
Dynamically Created `circle` not visible
我有以下代码。我可以通过inspect元素看到新创建的circle
。但在页面上是看不见的。
function drawCircle(x, y, r) {
var circle = document.createElementNS(null, 'circle');
circle.setAttributeNS(null, 'cx', x);
circle.setAttributeNS(null, 'cy', y);
circle.setAttributeNS(null, 'r', r);
circle.setAttributeNS(null, 'fill', 'red');
circle.setAttributeNS(null, 'stroke', 'black');
circle.setAttributeNS(null, 'stroke-width', '2');
document.getElementById("group").appendChild(circle);
}
drawCircle("50", "50", "30");
<svg id ="group" height="100" width="100"></svg>
SVG元素必须在SVG命名空间中创建。例如
function drawCircle(x, y, r) {
var circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttributeNS(null, 'cx', x);
circle.setAttributeNS(null, 'cy', y);
circle.setAttributeNS(null, 'r', r);
circle.setAttributeNS(null, 'fill', 'red');
circle.setAttributeNS(null, 'stroke', 'black');
circle.setAttributeNS(null, 'stroke-width', '2');
document.getElementById("group").appendChild(circle);
}
drawCircle("50", "50", "30");
<svg id ="group" height="100" width="100"></svg>
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 为effect Composer创建GodRays效果过程
- 从javascript创建一个列表
- onkeyup无法动态创建多个文本区域
- 如何使用javascript从主svg对象动态创建svg视图框
- 如何访问声音管理器2创建的声音对象
- 播放音频时创建一个跳动的圆圈
- jQuery circle菜单导航在切换关闭后创建小圆圈
- 使用JPlayer圆圈播放器创建播放列表
- Javascript 如何创建圆圈
- 为什么在我的 SVG 中说 .selectAll() D3 创建的圆圈是使用 .length 的 1 个元素
- Javascript和Canvas:绘制和删除线条以创建一个“呼吸”的圆圈
- 动态创建的“圆圈”不可见
- 在堆叠区域图表上创建圆圈
- 创建与圆圈时间相关的动画
- 在HTML/css/script中创建有3个部分的圆圈,并从每个部分执行动作
- 如何创建谷歌加圆圈与鼠标悬停效果
- 圆圈创建在以前的坐标在谷歌地图api
- 如何将angularjs动态文本输入与d3js相结合,创建svg圆圈进行过滤
- 如何使用d3 js在SVG文件上创建带有文本的圆圈