jQuery Animation - Smooth Size Transition

前端 未结 8 2213
天命终不由人
天命终不由人 2020-11-28 07:30

So this might be really simple, but I haven\'t been able to find any examples to learn off of yet, so please bear with me. ;)

Here\'s basically what I want to do:

8条回答
  •  猫巷女王i
    2020-11-28 07:59

    You can smooth out the jQuery animation using dequeue. Test for presence of class (set upon hover and removed on mouseOut animate callback) before staring new animation. When new animation does start, dequeue.

    Here's a quick demo.

    var space = ($(window).width() - 100);
    $('.column').width(space/4);
    
    $(".column").click(function(){
        if (!$(this).hasClass('animated')) {
            $('.column').not($(this).parent()).dequeue().stop().animate({width: 'toggle', opacity: '0.75'}, 1750,'linear', function () {});
        }
    
      $(this).addClass('animated');
        $('.column').not($(this).parent()).dequeue().stop().animate({width: 'toggle', opacity: '0.75'}, 1750,'linear', function () {
              $(this).removeClass('animated').dequeue();
    
          });
        $(this).dequeue().stop().animate({
            width:(space/4)
        }, 1400,'linear',function(){
          $(this).html('AGAIN');
        });
    });
    

    The demo is setup as 5 full-height columns, clicking any of the columns 2 thru 5 will animate toggle width of the other 3 and move the clicked element to the far left.

    enter image description here

    enter image description here

提交回复
热议问题