JScript code
r = 100;//半径
o = [x,y]//圆心
for(i=0;i<360;i++){//调整i的步长来求div的分布点坐标
angle = Math.PI / 180 * i;
x1[i]=o[0]+r*Math.sin(angle)
y1[i]=o[1]+r*Math.con(angle)
}
r = 100;//半径
o = [x,y]//圆心
for(i=0;i<360;i++){//调整i的步长来求div的分布点坐标
angle = Math.PI / 180 * i;
x1[i]=o[0]+r*Math.sin(angle)
y1[i]=o[1]+r*Math.con(angle)
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
div
{
width:100px;
height:100px;
border: 1px dotted red;
position:absolute;
overflow:auto;
}
</style></head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</body>
<script type="text/javascript">
/*
var x = Math.ceil(1024/2);
var y = Math.ceil(768/2);
r = 100;//半径
o = [x,y]//圆心
for(i=0;i<360;i++){//调整i的步长来求div的分布点坐标
angle = Math.PI / 180 * i;
x1[i]=o[0]+r*Math.sin(angle)
y1[i]=o[1]+r*Math.cos(angle)
}
*/
var x = Math.ceil(1024/2);
var y = Math.ceil(768/2);var r = 100;//半径
var o = [x,y]//圆心var oPosition = new Object();
oPosition.x = 0;
oPosition.y = 0;var obj_divs=document.getElementsByTagName("div");var angle = Math.PI / 180 * 360*Math.random();//随机角度for(var i=0; i<obj_divs.length; i++)
{
for(var k=0; k<=5; k++)
oPosition.x = o[0]+r*Math.sin(angle);
oPosition.y = o[1]+r*Math.cos(angle); obj_divs[i].style.left = oPosition.x + "px";
obj_divs[i].style.top = oPosition.y + "px";
}//------------------------------------//
function isInteractOnEachOther(oPos)
{
var bIsInteract = false;
for (var i=0; i<aX.length; i++)
{
if ( ((oPos.x>(aX[i]-iDivWidth))&&(oPos.x<(aX[i]+iDivWidth)))
&& ((oPos.y>(aY[i]-iDivHeight))&&(oPos.y<(aY[i]+iDivHeight))) )
{
bIsInteract = true;
break;
}
}
if (!bIsInteract)
{
aX[aX.length] = oPos.x;
aY[aY.length] = oPos.y;
}
return bIsInteract;
}
}
</script>
</html>
结果不成功
<body>
</body><script>
r = 100;//半径
o = [200,200]//圆心
x1=[]
y1=[]
for(i=0;i<360;i++){//调整i的步长来求div的分布点坐标
angle = Math.PI / 180 * i;
x1[i]=o[0]+r*Math.sin(angle)
y1[i]=o[1]+r*Math.cos(angle)
div = document.createElement("div")
div.style.top = y1[i]+"px"
div.style.left = x1[i]+"px"
div.style.width = "100px";
div.style.height = "100px";
div.style.position = "absolute";
div.style.border = "1px solid #EEE";
div.style.background = "#CCC";
document.body.appendChild(div);
}for(i=0;i<360;i+=30){//调整i的步长来求div的分布点坐标
angle = Math.PI / 180 * i;
x1[i]=o[0]+400+r*Math.sin(angle)
y1[i]=o[1]+r*Math.cos(angle)
div = document.createElement("div")
div.style.top = y1[i]+"px"
div.style.left = x1[i]+"px"
div.style.width = "100px";
div.style.height = "100px";
div.style.position = "absolute";
div.style.border = "1px solid #EEE";
div.style.background = "#CCC";
document.body.appendChild(div);
}
</script>
<body>
</body><script>
r = 100;//半径
o = [200,150]//圆心
x1=[]
y1=[]
for(i=0;i<360;i++){//调整i的步长来求div的分布点坐标
angle = Math.PI / 180 * i;
x1[i]=o[0]+r*Math.sin(angle)
y1[i]=o[1]+r*Math.cos(angle)
div = document.createElement("div")
div.style.top = y1[i]+"px"
div.style.left = x1[i]+"px"
div.style.width = "100px";
div.style.height = "100px";
div.style.position = "absolute";
div.style.border = "1px solid #EEE";
div.style.background = "#CCC";
document.body.appendChild(div);
}for(i=0;i<360;i+=30){//调整i的步长来求div的分布点坐标
angle = Math.PI / 180 * i;
x1[i]=o[0]+400+r*Math.sin(angle)
y1[i]=o[1]+r*Math.cos(angle)
div = document.createElement("div")
div.style.top = y1[i]+"px"
div.style.left = x1[i]+"px"
div.style.width = "100px";
div.style.height = "100px";
div.style.position = "absolute";
div.style.border = "1px solid #EEE";
div.style.background = "#CCC";
document.body.appendChild(div);
}
for(i=0;i<10;i++){//调整i的步长来求div的分布点坐标
angle = (Math.PI / 180 )* 360*Math.random();
x1[i]=o[0]+r*Math.sin(angle)
y1[i]=o[1]+300+r*Math.cos(angle)
div = document.createElement("div")
div.style.top = y1[i]+"px"
div.style.left = x1[i]+"px"
div.style.width = "50px";
div.style.height = "50px";
div.style.position = "absolute";
div.style.border = "1px solid #EEE";
div.style.background = "#CCC";
document.body.appendChild(div);
}
</script>
jf jf
jf