首先,您将在每个 for 循环中重复修改您唯一的现有圈子。
其次,每次迭代都将高度和宽度设置为 40 像素。
第三,您可能希望使用 SVG 图形,它为此类内容提供本机支持。以下是 SVG 的示例:
http://jsfiddle.net/5c6zy/1/
//HTML
<svg id='circles' xmlns="http://www.w3.org/2000/svg" version="1.1"></svg>
//Javascript
var centerX = 250;
var centerY = 250;
for(var count = 0; count < 20; count++){
var radius = count * 10;
makeAndPlaceCircle(radius);
};
function makeAndPlaceCircle(r){
// thx m93a: http://stackoverflow.com/a/16489845/1380669
var circles = document.getElementById('circles'); //Get svg element
var newElement = document.createElementNS("http://www.w3.org/2000/svg", 'circle');
newElement.setAttribute("cx", centerX);
newElement.setAttribute("cy", centerY);
newElement.setAttribute("r", r);
newElement.style.stroke = "#000"; //Set stroke colour
newElement.style.strokeWidth = "2px"; //Set stroke width
newElement.style.fill = "none"; //Set stroke colour
circles.appendChild(newElement);
};
//No CSS required, but you can define CSS classes and set them on the SVG circle elements, if you would like to e.g. change stroke, fill