圆形小球环形均匀分布代码实例

快乐打工仔 分类:实例代码

分享一段代码实例,它实现了小球环形围绕的效果。

并且小球是均匀分布的,代码实例如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.pipipi.net/" />
<title>犀牛前端部落</title>
<style type="text/css">
.centerDiv {
  width: 600px;
  height: 600px;
  margin: 0 auto;
  margin-top: 200px;
  position: relative;
}
.dashedCircle {
  height: 300px;
  width: 300px;
  border-radius: 100%;
  border: 1px dashed #494949;
  margin: 0 auto;
}
.circle, .circleCenter {
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: #fff;
  background: #97e49a;
  border-radius: 100%;
  position: absolute;
}
.circleCenter {
  width: 20px;
  height: 20px;
  line-height: 20px;
}
</style>
<script type="text/javascript">
window.onload = function () {
  var dx = 280,
                  dy = 130,
                        s = 180,//半径
                        x = Math.sin(0),
                        y = Math.cos(0),
                        dig = 2 * Math.PI / 12;
  var circle = document.querySelectorAll(".circle");
  for (var index = 0; index < 12; index++) {
    var x = Math.sin(index * dig);
    var y = Math.cos(index * dig);
    var topValue = Number(dy + y * s),
          leftValue = Number(dx + x * s);
    circle[index].style.top = topValue + "px";
    circle[index].style.left = leftValue + "px";
  }
  var circleCenterObj = document.querySelector(".circleCenter");
  circleCenterObj.style.top = Number(dy) + 10;//10是中心小圆半径
  circleCenterObj.style.left = Number(dx) + 10;
}
</script>
</head>
<body>
  <div class="centerDiv">
    <div class="dashedCircle"></div>
    <div class="circleCenter"></div>
    <div class="circle">7</div>
    <div class="circle">6</div>
    <div class="circle">5</div>
    <div class="circle">4</div>
    <div class="circle">3</div>
    <div class="circle">2</div>
    <div class="circle">1</div>
    <div class="circle">12</div>
    <div class="circle">11</div>
    <div class="circle">10</div>
    <div class="circle">9</div>
    <div class="circle">8</div>
  </div>
</body>
</html>

圆形小球环形均匀分布代码实例,这样的场景在实际项目中还是用的比较多的,关于圆形小球环形均匀分布代码实例就介绍到这了。

圆形小球环形均匀分布代码实例属于前端实例代码,有关更多实例代码大家可以查看

回复

我来回复
  • 暂无回复内容