Javascript 无法在变量中设置高度
我在页脚中有这个,所以当所有内容加载时。警报给出了正确的结果,但当我将相同的变量应用于“容器”的高度时,该警告无效Javascript 无法在变量中设置高度,javascript,jquery,Javascript,Jquery,我在页脚中有这个,所以当所有内容加载时。警报给出了正确的结果,但当我将相同的变量应用于“容器”的高度时,该警告无效 $(document).ready(function() { var original_height = $("#container").height(); var newDistance = $(".detta .content").outerHeight(true); var total = original_height + newDistance;
$(document).ready(function() {
var original_height = $("#container").height();
var newDistance = $(".detta .content").outerHeight(true);
var total = original_height + newDistance;
alert(total);
$(".detta .box").animate({top: newDistance});
$("#container").height(total);
});
容器在css中没有任何设置的高度
我做错了什么?而是:
$("#container").height(total);
试试这个:
$("#container").css("height",total);
祝你好运
$(function() {
var original_height = $("#container").height();
var newDistance = $(".detta .content").outerHeight(true);
var total = original_height + newDistance;
$(".detta .box").animate({top: newDistance}, function(){
$("#container").height(total);
});
});
宾果!新的容器高度必须被触发,所以我只是在框动画发生后应用它您是否尝试将代码包装到$function{…};准备好了吗?声音不需要了吗?在所有内容之后,它在页脚中。。或者它仍然需要它吗?这取决于你的容器是否正在加载图像。例如,刚刚尝试过,没有任何变化。我不明白,screngrab在photoshop中给出了高度419,但警告说589,不明白它实际上是在加载来自vimeo的图像和视频。。。使用更新了问题。准备好了,我得到了相同的结果,但这应该没有任何区别。