1

3 列のフローティング div を使用して、1 行の 3 列から最大の高さを取得し、3 つの div すべてを同じ高さにするスクリプトを作成しました。次に、行ごとにそれを繰り返します。スクリプトは正常に動作しますが、価格帯やブランドなどの選択に応じて特定の div を非表示または表示するカスタム フィルター システムを JQuery で構築しました。

フィルターを使用している場合、一番上の行の列 2 を削除し、2 番目の行の列 4 を一番上の行に移動させます。コードに列 2 を残して、高さ/列チェック スクリプトを再実行しても機能しません。

だから私がしようとしているfilter(':nth-child(3n-2)')のは、:nth-child 選択から隠されているすべての div をスキップする if ステートメントを追加する場所です。

内部で関数を使用できることは理解していますfilter();が、それは私にとって新しい関数であるため、正確に使用する方法がわかりません。

ここに私の作業コードがあります:

var $sections = $('.section-link');
$sections.filter(':nth-child(3n-2)').each(function () {
    var $this = $(this),
        $els = $this.nextAll(':lt(2)').addBack();
    var sectionheight = new Array();
    $els.each(function () {
        var value = $(this).find('.section-title').height();
        sectionheight.push(value);
    });
    var newsectionheight = Math.max.apply(Math, sectionheight);
    $els.find('.section-title').height(newsectionheight);
})

JSfiddle の例

これまでのところ、このようなものを使用しようとしています:

$sections.filter(function() {
   return $(this).css('display') !== 'none';
}, ':nth-child(3n-2)')
4

1 に答える 1

0

:nth-child を呼び出す前に css プロパティを返すことで、なんとか機能させることができました

function makeheight(){
var $sections = $('.section-link');

    $sections.filter(function() {
   return $(this).css('display') == 'block';
}, ':nth-child(3n-2)').each(function () {

        var $this = $(this),
            $els = $this.nextAll(':lt(2)').addBack();
        var sectionheight = new Array();
        $els.each(function () {
            var value = $(this).find('.section-title').height();
            sectionheight.push(value);
        });
        var newsectionheight = Math.max.apply(Math, sectionheight);
        $els.find('.section-title').height(newsectionheight);
    });


}
于 2013-09-18T11:58:45.063 に答える