我有一个带有 9 个链接的图像精灵。在动态找出值并相应移动之后,我没有指示每个链接的值,而是尝试在 jQuery 中制作动画。
这是标记:
<div class="compass">
<a class="north" href="#" alt="North"> </a>
<a class="east" href="#" alt="East"> </a>
<a class="south" href="#" alt="South"> </a>
<a class="west" href="#" alt="West"> </a>
<a class="northeast" href="#" alt="North East"> </a>
<a class="southeast" href="#" alt="South East"> </a>
<a class="southwest" href="#" alt="South West" > </a>
<a class="northwest" href="#" alt="North West"> </a>
</div>
和jQuery:
var westLeft = +2150;
var westTop = +350;
$(".compass a").click(function(){
var target = $(this).attr('class');
var destinationTop = target + 'Top';
var destinationLeft = target + 'Left';
$('.map').animate({
top: destinationTop,
left: destinationLeft
}, 1000, 'swing', function(){
//we're done!
});
});
所以当我点击西链接时,我让destinationTop动态显示westTop,但不是westTop的实际值。与destinationLeft 相同。
非常感谢你。