若要出點的位置沿一個圓則可以使用公式:
c^2 = a^2 + b^2
其中c =半徑,a爲中心verticle距離,b爲中心的水平距離。
因此,瞭解這一點,我構建了一個非常人爲的例子供您回顧。請注意,有幾件事可以幫助提高性能,例如緩存半徑平方,但爲了避免演示覆雜化,我放棄了這一點。
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
#wrapper { position: relative; }
#curved {
position: absolute;
left: 200px;
-moz-border-radius-bottomleft: 200px;
-webkit-border-bottom-left-radius: 200px;
border-bottom-left-radius: 200px
border: 1px solid red;
padding: 100px;
background: red;
}
#magiclist { padding-top: 15px; width: 325px; list-style-type: none; }
li { text-align: right; }
</style>
<script>
$(function() {
/* c^2 = a^2 + b^2, c = radius, a = verticalShift, b = horizontalShift */
/* Therefore b = sqrt(c^2 - b^2), so now we can calculate the horizontalShift */
var radius = 200;
var verticalShift = 0;
var horizontalShift = 0;
/* iterate over the list items and calculate the horizontalShift */
$('li').each(function(index, element) {
/* calculate horizontal shift by applying the formula, then set the css of the listitem */
var horizontalShift = Math.sqrt(Math.pow(radius,2) - Math.pow(verticalShift,2));
$(element).css('padding-right', horizontalShift + 'px');
/* need to track how far down we've gone, so add the height of the element as an approximate counter */
verticalShift += $(element).height();
});
});
</script>
</head>
<div id="wrapper">
<div id="curved">test</div>
<ul id="magiclist">
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
</ul>
</div>
</html>
這是我懷疑會有點棘手的事情之一:-) – Pointy 2011-05-31 15:00:35
什麼是邊界半徑代碼? – oblig 2011-05-31 15:03:42
您是否嘗試使用解析幾何中的公式?如果'[m,n]'是半徑設置點的座標,'r'是半徑,則對於曲線上的每個點('[x,y]'),以下情況爲真:'(xm )^ 2 +(yn)^ 2 = r^2'。 – duri 2011-05-31 15:09:43