你只需要破坏旧的三角学书并做一点 sin/cos。这是我能想到的最简单的例子。证据在布丁中' http://jsfiddle.net/67zMe/5/
HTML:创建要放置在圆圈上的项目列表。
<ul id="circle-list">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
</ul>
CSS:奠定一些基础的 CSS。
#circle-list
{
width:300px;
height:300px;
position:relative;
margin:0;
padding:0;
list-style:none;
border:solid 2px #ccc;
left:50%;
top:20px;
margin-left:-150px;
}
#circle-list li
{
display:block;
position:absolute;
background:#ccc;
font-family:arial;
color:#666;
text-align:center;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
width:30px;
height:30px;
line-height:30px;
/** offset top and left half the item's width so that as we position the items, it is from their center point. **/
margin:-15px 0 0 -15px;
}
JS:这就是魔法发生的地方。Javascript来拯救。
// Get degrees between each item, based on total items.
var angleSteps = 360 / $('#circle-list li').length;
// base angle to increment, which will rotate entire list.
var baseAngle = 0;
// center of the circle, relative to parent <ul>
var center = 150;
// distance to place each item from the center
var distance = 100;
function updateListPositions()
{
// loop through each list item and place it on the circle based on it's angle
$('#circle-list li').each(function(index, element)
{
var angle = baseAngle + (index * angleSteps);
var x = distance * Math.cos(angle * (Math.PI / 180));
var y = distance * Math.sin(angle * (Math.PI / 180));
$(element).css({left:center+x, top:center+y});
});
}
// set a timer to continually increment the base angle, which rotates the circle.
// this could easily be changed to increment the circle based on scroll delta
var stepInterval = setInterval(stepAngle, 25);
function stepAngle()
{
baseAngle++;
// update position as base angle changes
updateListPositions();
}