对于div的高度变化,我有下面的javascript。然而,我不知道如何调整速度时,div显示。我知道500是当div的高度改变到30 it时的速度,但当它变回100%时,我不知道如何控制它。有人能帮忙吗?
$(document).ready(function(){
$("#mydiv").click(function(){
var $this = $('#mydiv_2');
$this.animate({height: $this.height() == 30 ? '100%' : 30}, 500);
});
});发布于 2013-10-16 05:43:35
$this.animate({height: $this.height() == 30 ? '100%' : 30}, 500);第二个属性是以毫秒为单位的速度。
发布于 2013-10-16 05:42:56
看看jQuery文档。animate()的第二个参数控制速度(越大越慢)。
编辑:如果您希望在div隐藏和显示时以不同的速度显示,请尝试如下:
if ($this.height() == 30) {
$this.animate({height: '100%'}, 1200);
} else {
$this.animate({height: 30}, 500);
}发布于 2013-10-16 05:43:50
像这样在动画中使用slow
$this.animate({height: $this.height() == 30 ? '100%' : 30},'slow');如果你需要更慢的时间,用毫秒来代替慢。
$this.animate({height: $this.height() == 30 ? '100%' : 30}, 1200);这将使其慢下来1.2秒,相应地调整:)
还可以查看Jquery动画以获得更多选项
https://stackoverflow.com/questions/19396010
复制相似问题