使用javascript buggy在圆圈周围排列点

时间:2015-10-16 10:25:22

标签: jquery html css3

我正在尝试围绕一个圆圈排列一个圆点。但我得到了越野车的结果。某些度数(顶部和底部)没有正确定位。会是什么问题?

如何解决这个问题?



$(function(){
  
  var globe = $('#center');
  var width = globe.width() / 2 ;
  var height = globe.height() / 2;
  var point = $('.point').width();
  var pointer = $('<div />', {class:'test'});

  
  for(var i = 1; i <=  360; i++) {
    
    pointer.clone().css({
      left: width  + (width) * Math.cos(i * Math.PI / 180),
      top: height  + (height + point) * Math.sin(i * Math.PI / 180)
    }).appendTo('#center');
    
  }
     
 
});
&#13;
#center {
    width:300px;
    height:300px;
    border-radius:50%;
    border:1px solid red;
    position:relative;
    left:200px;
    top:100px;
}

.test {
  
  width:0.1em;
  height:0.1em;
  background:gray;
  position:absolute;
  border-radius:50%;
  
}

.point {
  width:0.5em;
  height:0.5em;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="center"></div>
<div class="point"></div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:3)

替换:

  top: height  + (height + point) * Math.sin(i * Math.PI / 180)

使用:

  top: height  + (height) * Math.sin(i * Math.PI / 180)