1

タグをクリックすると、それぞれの div が表示され、アニメーション化されます。同じタグをもう一度クリックすると、それぞれの div が 20 のままである場合、-30 のままにする必要があります。フィドル

jQuery

$('li').click(function(e){
   var li= $(this).index()
var off= $(this).offset().top;
    $('div').each(function(){
        $(this).animate({left:'-30px',top:off},500, function(){
         $('div').eq(li).animate({left:'20px',top:off},500)
        })
    })    


})
4

1 に答える 1

1

div -30px を左に移動した後、実行しているアニメーションを使用したくないだけですか?

$('li').click(function(e){
    var li = $(this);
    var index = li.index()
    var topOffset = li.offset().top;
    var isOpen = li.toggleClass('open').hasClass('open');
    li.siblings().removeClass('open');
    $('div').each(function(){
        $(this).animate({ left: '-30px', top: topOffset }, 500, function(){
            if(isOpen) {
                $('div').eq(index).animate({ left: '20px', top: topOffset}, 500);
            }
        });
    });
});

デモ: http://jsfiddle.net/ckDHz/3/

于 2013-10-22T05:14:28.737 に答える