相关疑难解决方法(0)

Jquery - 动画高度切换

我在屏幕顶部有一个10px的条,当点击时,我希望它的动画高度为40px,然后再次点击,动画回到10px.我尝试更改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; }
Run Code Online (Sandbox Code Playgroud)

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');
  });
});
Run Code Online (Sandbox Code Playgroud)

jquery height attr jquery-animate

38
推荐指数
3
解决办法
17万
查看次数

标签 统计

attr ×1

height ×1

jquery ×1

jquery-animate ×1