$ 函数根据元素所在容器的高度切换元素

$ function that toggles elements depending on height of the container that it is in

我有这个功能需要根据#recent 容器的高度显示行数。

假设我们不知道#recent 的高度,但 .row 的高度是 const 34px。问题是我们需要隐藏所有第 n 个子行(n+ 取决于数字)。

假设如果#recent 的高度是 100 像素,我们只需要显示 2 行(因为如果我们显示 3 行,高度需要超过 102 像素)

var thisFunc= function() {

    var h = $('#recent').height();
    var nr = Math.round(parseInt(sectionHeight) / parseInt($('.row').height()));

    var x = nr - 1;
    var nth = $('.row:nth-child(n+'+x+')');
    nth.addClass('hideMe');

}

thisFunc();
$(window).resize(thisFunc);

我们现在只显示所需的行数。但是 问题是当我们增加 window 的大小时它们不会出现回来 。他们添加了 'hideMe' class,但我不确定如何 切换 它。

有什么想法吗?谢谢!

var thisFunc= function() {
// reset childs
$('.row').removeClass('hideMe');


var h = $('#recent').height();
var nr = Math.round(parseInt(sectionHeight) / parseInt(

$('.row').height()));

    var x = nr - 1;
    var nth = $('.row:nth-child(n+'+x+')');
    nth.addClass('hideMe');

}