jquery实现以原点为中心圆线上都是div圆

来源:互联网 发布:侠客风云传mod数据 编辑:程序博客网 时间:2024/05/17 01:09
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>圆形周围被圆包围</title><script type="text/javascript" src="jquery-1.5.1.min.js"></script><script type="text/javascript">$(function(){//中心点横坐标var dotLeft = ($(".container").width()-$(".dot").width())/2;//中心点纵坐标var dotTop = ($(".container").height()-$(".dot").height())/2;//起始角度var stard = 0;//半径var radius = 300;//每一个BOX对应的角度;var avd = 360/$(".box").length;//每一个BOX对应的弧度;var ahd = avd*Math.PI/180;//设置圆的中心点的位置$(".dot").css({"left":dotLeft,"top":dotTop});$(".box").each(function(index, element){            $(this).css({"left":Math.sin((ahd*index))*radius+dotLeft,"top":Math.cos((ahd*index))*radius+dotTop});        });})</script><style type="text/css">*{margin:0;padding:0;}.container{position:relative;width:700px;height:800px; margin:0 auto; border:1px solid #F00;}.box{position:absolute;width:60px;height:60px;background:#000; border-radius:50%;color: #fff;text-align: center;}.dot{ position:absolute;width:100px;height:100px;background:#F00;}p{word-break:break-word;}</style></head><body><div class="container"><div class="dot">eeeee</div><div class="box">eeeee</div><div class="box">eeeee</div><div class="box"><p>eefafafeeffffe</p></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div></div></body></html>

效果图:


0 0
原创粉丝点击