39,087
社区成员
发帖
与我相关
我的任务
分享
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
<style type="text/css">
#box {
position: relative;
width: 500px;
height: 500px;
background: #CCC;
}
#box div {
position: absolute;
border: 1px solid #000;
display: inline;
background: #FFF;
padding: 10px;
}
</style>
</head>
<body>
<div id="box">
<div>aaaaa</div>
<div>bb</div>
<div>ccccccc</div>
<div>ddd</div>
<div>eeeee</div>
</div>
<script type="text/javascript">
(function () {
var box = document.getElementById("box");
var div = box.getElementsByTagName("div");
var cx = box.offsetWidth >> 1;
var cy = box.offsetHeight >> 1;
var len = div.length;
var radius = 200;
var loop = 0;
function draw() {
loop += 0.02;
for (var i = 0; i < len; i++) {
div[i].style.left = (Math.sin((Math.PI*2)*(i/len)+loop)*radius) + cx - (div[i].offsetWidth>>1) + "px";
div[i].style.top = (-Math.cos((Math.PI*2)*(i/len)+loop)*radius) + cy - (div[i].offsetHeight>>1) + "px";
}
}
var timer = setInterval(draw, 50);
for (var i = 0; i < len; i++) {
div[i].onmouseover = function () {
clearInterval(timer);
}
div[i].onmouseout = function () {
timer = setInterval(draw, 50);
}
}
})();
</script>
</body>
</html>