1

我是 jquery 的新手

这是我想要使用 jquery 实现的目标:如果 div id 1 的高度大于窗口高度,则仅将类设置为 div id 1

<div id="1">some text</div>
<div id="2">some text</div>
<div id="3">some text</div>

谢谢

4

1 回答 1

2

这是一个示例:

$(function() {
    $(window).resize(function() { //whenever window is resized
        var el = $('#1');         //caches the selector
        if (el.height() > $(window).height())   //if #1.height > window.height
            el.addClass('LargerThanWindow');    //add a class to it
        else
            el.removeClass('LargerThanWindow'); //else remove the class
    }).resize(); //triggers the resize handler which we just set inside the 
});              //DOM ready event

Fiddle
垂直调整窗口大小,您将看到应用/删除的类。

于 2012-08-02T17:23:02.857 回答