gpt4 book ai didi

Jquery - 动画高度切换

转载 作者:行者123 更新时间:2023-12-03 21:28:20 25 4
gpt4 key购买 nike

我在屏幕顶部有一个 10 像素的条,当单击该条时,我希望它以动画方式显示到 40 像素的高度,然后如果再次单击,则以动画方式返回到 10 像素。我尝试更改 div 的 id,但它不起作用。我怎样才能让它发挥作用,或者有更好的方法吗?

正文 html:

<div id="topbar-show"></div>

CSS:

#topbar-show { width: 100%; height: 10px; background-color: #000; }
#topbar-hide { width: 100%; height: 40px; background-color: #000; }

JavaScript:

$(document).ready(function(){
$("#topbar-show").click(function(){
$(this).animate({height:40},200).attr('id', 'topbar-hide');
});
$("#topbar-hide").click(function(){
$(this).animate({height:10},200).attr('id', 'topbar-show');
});
});

最佳答案

尝试一下:

$(document).ready(function(){
$("#topbar-show").toggle(function(){
$(this).animate({height:40},200);
},function(){
$(this).animate({height:10},200);
});
});

关于Jquery - 动画高度切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4965004/

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