forked from fanggogo/gitContent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.div画圆.html
44 lines (36 loc) · 965 Bytes
/
1.div画圆.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="" />
<meta name="copyright" content="" />
<title></title>
<style>
#div1 {width:300px; height:300px; border:1px solid black; position:absolute; left:100px; top:150px; border-radius:50%;}
#div1 span {width:50px; height:50px; border:1px solid red; position:absolute; border-radius:50%; line-height:50px; text-align:center; font-size:20px;}
</style>
<script>
window.onload=function ()
{
var oDiv=document.getElementById('div1');
var r=oDiv.offsetWidth/2;
var N=9;
for(var i=0;i<N;i++)
{
var oSpan=document.createElement('span');
oDiv.appendChild(oSpan);
a=i*(360/N);
//算位置
var x=r+Math.sin(a*Math.PI/180)*r;
var y=r-Math.cos(a*Math.PI/180)*r;
oSpan.style.left=x-oSpan.offsetWidth/2+'px';//减去span本身的半径
oSpan.style.top=y-oSpan.offsetHeight/2+'px';
oSpan.innerHTML=i+1;
}
};
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>