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 に答える