代码之家  ›  专栏  ›  技术社区  ›  eozzy

动画div显示/隐藏(jQuery)

  •  2
  • eozzy  · 技术社区  · 14 年前
    $('.button').click(function() {
        $('#small-form').animate({
            width: ['toggle', 'swing'],
            height: ['toggle', 'swing'],
            opacity: 'toggle'
        }, 5000, 'linear');
        $('#big-form').animate({
            width: ['toggle', 'swing'],
            height: ['toggle', 'swing'],
            opacity: 'toggle'
        }, 5000, 'linear');
    });
    

    ... 这隐藏了两个元素,我想隐藏小的和显示大的形式。

    谢谢!

    2 回复  |  直到 14 年前
        1
  •  4
  •   Reigel Gallarde    14 年前

    有了你的密码,就要看情况了。如果两个窗体都可见,则显示这两个窗体。Toggle的意思是做相反的事,-如果它是隐藏的,显示它-如果它的高度大于0,使它为0。

    建议:

    1.)您的代码可以简化为。

    $('.button').click(function() {
        $('#small-form, #big-form').animate({
            width: ['toggle', 'swing'],
            height: ['toggle', 'swing'],
            opacity: 'toggle'
        }, 5000, 'linear');
    });
    

    $('#small-form').hide()

        2
  •  1
  •   jknair    14 年前

    试试这个:

    $('.button').click(function() {
    $('#small-form').animate({
        width: ['toggle', 'swing'],
        height: ['toggle', 'swing'],
        opacity: 'toggle'
    }, 5000, 'linear',
    complete: $('#big-form').animate({
        width: ['toggle', 'swing'],
        height: ['toggle', 'swing'],
        opacity: 'toggle'
    }, 5000, 'linear');
    });
    

    使用complete:动画完成后调用的函数。