gpt4 book ai didi

jQuery 切换点击

转载 作者:行者123 更新时间:2023-12-01 01:55:49 26 4
gpt4 key购买 nike

假设我需要一个元素在单击时呈现动画。为此,我只需:

$('#header .icon').click(function() {
$('#header form').animate({width:'195px'});
});

但是我该如何做到这一点,以便当我再次单击该元素时会发生相反的动画? (例如,动画宽度:0px;)

最佳答案

您可以使用.toggle()像这样:

$('#header .icon').toggle(function() {
$('#header form').animate({width:'195px'});
}, function() {
$('#header form').animate({width:'0px'});
});

如果它最初是out,你可以像这样切换它的宽度:

$('#header .icon').click(function() {
$('#header form').animate({width:'toggle'});
});

关于jQuery 切换点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3505323/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com