我在屏幕顶部有一个高度为10像素的条,希望在单击时可以将其动画到40像素高度,再次单击时则动画回到10像素。我试图改变div的id,但它没有生效。有什么方法可以使它工作,或者是否有更好的方法?
body 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:
这是一个HTML标记,表示在其中包含的文本内容是JavaScript代码。它可以用于将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');
});
});