jQuery问题与height()和resize() [英] Jquery problem with height() and resize()

查看:99
本文介绍了jQuery问题与height()和resize()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据文档的高度为元素指定特定的高度,并在文档尺寸是否更改的情况下保持该高度:

I need to give an element a specific height based on document's height and keep it whether the document size changes:

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

});

现在,当我手动调整浏览器的大小时,它的工作原理像一个超级按钮,但是在页面加载时,文档大小的计算方式不正确,因此div的高度也是错误的.我试图强制将$(windows).resize()作为最后一条语句(作为测试,即使有几秒钟的延迟也是如此),但这无法正常工作,因为jQuery在手动调整大小后只能识别正确的高度.

Now, when I manually resize the browser it works like a charm, but at page load the document size is calculated in a wrong way so that the div's height is also wrong. I've tried to force a $(windows).resize() as last statement (as a test, even with a delay of seconds), but this doesn't work as jQuery only recognized the right height after a manual resize.

此外,通过双击或通过窗口的调整大小"按钮(Chrome,Windows)调整窗口大小,似乎并没有像拖动窗口边缘那样触发调整大小"事件.

Also, resizing the window with a double click or via the "resize" button of the window (Chrome, Windows) it doesn't seem to trigger the "resize" event as dragging the window edges does.

有帮助吗?

推荐答案

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

To calculate the height, try replacing document by window:

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

    });

这篇关于jQuery问题与height()和resize()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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