我在屏幕顶部有一个 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');
});
});