$('.container').animate({ 'height': el.height() }, { duration: 300});
所以el
的高度可以小于或大于.container
的高度。
当当前高度与我正在制作动画的高度之间的差异较大时,如何才能使效果持续时间更长?
$('.container').animate({ 'height': el.height() }, { duration: 300});
所以el
的高度可以小于或大于.container
的高度。
当当前高度与我正在制作动画的高度之间的差异较大时,如何才能使效果持续时间更长?
var newHeight = el.height(),
oldHeight = $('.container').height();
$('.container').animate({height: newHeight}, Math.abs(newHeight-oldHeight)*5);
将魔法常数更改5
为任何看起来合理的值。您没有提供计算持续时间的标准;您可以将它与 绑定Math.min(/*above expression*/, maxDuration)
,或者它不应该是线性的,而是对数的。你可以很容易地自定义它。虽然这是一个很好的起点。
if ($(.container).height() - $(el).height() > 0)
{
// Whatever you want to do if the container is higher than el
}
else
{
// Other case
}
不确定它是否是正确的 JS 语法,但它应该可以工作。
编辑:没关系,看看戴文的回答。
$('.container').animate({height:el.height()},($(this).height()-el.height()>el.height())?3000:100);