高度()和resize()的Jquery问题

我需要根据文档的高度为元素指定一个特定的高度,并保持文档大小的变化:

$(document).ready(function () { $('#descriptive_news_text').height(($(document).height() - 325)); $(window).resize(function () { $('#descriptive_news_text').height(($(document).height() - 325)); }); }); 

现在,当我手动调整浏览器的大小时,它就像一个魅力,但在页面加载时,文档大小的计算方式是错误的,因此div的高度也是错误的。 我试图强制$(windows).resize()作为最后一个语句(作为测试,即使有几秒的延迟),但这不起作用,因为jQuery在手动resize后才识别正确的高度。

此外,通过双击或通过窗口(Chrome,Windows)的“resize”按钮调整窗口大小,它似乎不会像拖动窗口边缘那样触发“resize”事件。

有帮助吗?

要计算高度,请尝试按窗口替换文档:

  $(document).ready(function () { $('#descriptive_news_text').height(($(window).height() - 325)); $(window).resize(function () { $('#descriptive_news_text').height(($(window).height() - 325)); }); }); 

像这样的东西似乎对我来说很好:

 $(function() { $("div#test").css("height", ($(document).height() - 325) + "px"); });