我試圖計算與類名alt
每個跨度元件的寬度,減去寬度,然後從該計算中減去另一個50像素:計算多發性元素寬度&減去它們的document.ready
<ul class="items">
<li class="product1 alt"><a href=""><span>Televisions</span></a></li>
<li class="product2"><a href=""><span>MP3 Players</span></a></li>
<li class="product3 alt"><a href=""><span>Speakers</span></a></li>
</ul>
而且我的jQuery:
function moveIt() {
var diamond = $("#ir-content li.alt a span").width();
$("#ir-content li.alt a span").css("left","-" + theMath - "50px");
alert(theMath);
}
moveIt();
演示:http://jsfiddle.net/rxw3B/ – 2011-12-18 02:01:57