我有5个图像,点击时我试图将它们相邻,相距50px进行动画处理。每个以前的元素jQuery margin-left
目前我正在动画第一个孩子,剩下的所有其他人都是50px,但所有人都在彼此之上。
这里是我的脚本:
var fadedur = 200,
fadeop = 0.5,
imgwidth = 220,
imgleft = 40,
imgfirst = -200,
imgfh = -100;
$('img').on('click', function(){
$('img').css('position','absolute').css('display','block');
$('.cs').find(':first-child').stop().animate({
"marginLeft": imgfirst,
"margin-top": imgfh,
}, 300);
$('.cs').find(':first-child').next('img').each(function() {
$(this).stop().animate({
"marginLeft": imgfirst + imgwidth + imgleft, // imgfirst should
"margin-top": imgfh, // be something that
}, 300); // states prev()
});
});
,这是我的小提琴:http://jsfiddle.net/STgQC/
我试图让他们看起来像这样:
所以基本上我需要东西会说:
动画到上一个元素的位置+图像宽度+ 50px左侧。
如果第一图像* *需要做一些不同的东西,你也可以使用.nextAll( 'IMG')来在第一个图像之后获得完整的图像集合。 – samiz 2012-04-28 00:45:24