动画的持续时间取决于元素的高度

duration of animation depends on height of element

本文关键字:高度 元素 持续时间 动画 取决于      更新时间:2023-09-26

我想向下滑动元素,它的持续时间必须取决于高度。例如,如果高度为2000px,持续时间也必须为2000

这是我的js

var element = document.getElementById('detail-'+thisID),
style = window.getComputedStyle(element),
content_height = style.getPropertyValue('height');
var height_js=parseInt(content_height, 10);
$('#wrap #detail-'+thisID).delay(700).slideDown(height_js);

我走对了吗?如果是,错误在哪里?

如果你已经在使用jquery,你可以使用jquery .height:

$('#wrap #detail-'+thisID).delay(700).slideDown($('#wrap #detail-'+thisID).height());

同样,在你的代码中,你应该只使用document.getElementById('detail-'+thisID'),不带后面的#,这只是一个jquery选择器,用于识别应该通过Id搜索的元素。