微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用jquery从下往上动画更改div高度

无论如何,我可以设置从底部到顶部而不是从上到下的div盒高度的变化动画?

这个div框是绝对定位的,对它下面的内容有点像窗帘.

最佳答案
为什么不使用slideUp()/ slideDown():

因为如果注册了多个/快速鼠标操作,它会容易出错.

尝试在演示中,即使使用.stop()方法也无法实现如下结果:

以下是使用.animate()和高度切换的略微修改
(只需要:position:absolute; bottom:0px; display:none;)

demo 1 (a nice way to do it)

$('.Box').hover(function(){
  $(this).find('.curtain').stop().animate({height: 'toggle'});
});

demo 2

另一种方式是:

var BoxHeight = $('.Box').innerHeight();  // get element height

$('.curtain').css({top:BoxHeight}); // push 'curtain' down

$('.Box').hover(function(){
  $(this).find('.curtain').stop().animate({top: 0});  // animate to desired top distance
},function(){
  $(this).find('.curtain').stop().animate({top: BoxHeight}); // and on mouSEOut - back down
});

原文地址:https://www.jb51.cc/jquery/428080.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐