Jquery调整文档高度 [英] Jquery resize document height

查看:98
本文介绍了Jquery调整文档高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的jQuery / JS代码有点麻烦。

I'm having a little trouble with my jQuery/JS code.

每当窗口调整大小时,应该运行stretch函数。

Whenever the window resizes, the "stretch" function should be run.

function stretch() {
    var stretch_elem = $('.stretch');
    if (stretch_elem.length) {
        var h = $(document).height() - stretch_elem.offset().top - 70;
        stretch_elem.height(h);
    }
}

$(window).resize(stretch);

但是,当我调整窗口大小时,发生了一些奇怪的事。

But something strange is happening, when I resize the window. The element I'm stretching is just getting longer and longer, even if I upsize the window and the document height is getting lower.

我在这里做错了什么?

提前感谢。

推荐答案

必须在设置新高度之前添加 stretch_elem.height(0); 。没想到我需要这样做。但它现在工作。

Just fixed it. Had to add stretch_elem.height(0); before setting the new height. Didn't think I needed to do that. But it's working now.

这篇关于Jquery调整文档高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆