3個のボックスのサイズを検出するjQueryスクリプトを実行しました。私は最大のの高さを(それは動作する)検出し、私は3つのボックスに最大のサイズを追加することができます。jQuery 3個のアイテムを比較して最大のサイズを追加
ページが読み込まれたときにのみ動作します。私はのサイズをとしますが、console.log(maxHeight)
を実行すると、ウィンドウを縮小しても常に同じ値になります。そして、私の箱は収まりません。
私を助けることができますか?
は
$(window).on("resize", function() {
var maxHeight = 0;
$('.sliderBlog').each(function(){
var thisH = $(this).height();
if (thisH > maxHeight) { maxHeight = thisH; }
});
$('.sliderBlog').height(maxHeight)
}).resize();
これは、 'maxHeight'が' resize'で呼び出す無名関数のローカルなのでです。 – caisah
'$(window)... 'からmaxHeightを移動してください。 – mehulmpt
' setTimeout'でresizeコールバックの呼び出しをデバウンスする必要があります。あなたは多くの呼び出しでブラウザをスパムしたくありません。 コードを関数でより表現力豊かにすることができます。可能であれば、グローバルな状態は避けるべきです。 –