将div放在一个圆圈中 [英] placing divs in a circle

查看:183
本文介绍了将div放在一个圆圈中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码将div放在一个圆圈内。但是,我想旋转圆圈以更改圆圈顶部的div序列。

I have the following code which places divs around a circle. However, I want to rotate the circle to change the sequence of divs from the top of the circle.

function drawCircle(selector, center, radius, angle, x, y)
    {


    var total = $(selector).length;
    var alpha = Math.PI * 2 / total;

    $(selector).each(function(index)
    {
        var theta = alpha * index;
        var pointx = Math.floor(Math.cos( theta ) * radius);
        var pointy = Math.floor(Math.sin( theta ) * radius );


        $(this).css('margin-left', pointx + x + 'px');
        $(this).css('margin-top', pointy + y + 'px');
    });

   }


  $(document).ready(function()
  {


   drawCircle('.box', 0, 250, 0, 500, 500);

  });


推荐答案

var theta = Math.PI/2 - alpha * index;

这很难:p

这篇关于将div放在一个圆圈中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆