【发布时间】:2012-08-11 20:52:49
【问题描述】:
我正在尝试在 jQuery 中组合我自己的动画下拉菜单,但结果很奇怪。我有一个包含按钮 DIV 和菜单 DIV 的容器,其想法是(在鼠标悬停时)容器 DIV 和菜单 DIV 都按高度缩放,菜单 DIV 获得 CSS {'display', 'block'}。在容器 DIV 的鼠标移出(它应该已经缩放高度以包含按钮和菜单 DIV)我希望 DIV 缩放回它们的原始高度和菜单 DIV 以获得 CSS {'display','none '}。
现在的问题是,在所有内容都放大之后,不是在按比例放大的容器(高度:300 像素)的鼠标移出时缩小,而是在鼠标移出容器的原始高度(高度:100 像素)之后开始缩放,而不是新的。
代码如下:
$('.container').mouseover(function(){
$('.bob').css('display','block');
$('.bob').animate({height: '200px'});
$(this).animate({height: '300px'});
});
$('.container').mouseout(function(){
$('.bob').animate({height: '0'},
function(){
$('.bob').css('display','none');
});
$(this).animate({height: '100px'});
});
【问题讨论】:
-
为动画添加回调函数。在此回调函数中,您再次显式设置高度。
标签: jquery css jquery-animate mouseover mouseout