首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >过滤器:nth--忽略css显示为空的位置。

过滤器:nth--忽略css显示为空的位置。
EN

Stack Overflow用户
提问于 2013-09-18 11:46:34
回答 1查看 880关注 0票数 1

我有一个脚本,在3列中使用一些浮动的div,从1行的3列获得最大的高度,并使所有的3 div都具有相同的高度。然后,它对每一行重复它,脚本工作很好,但是我已经在JQuery中构建了一个定制的过滤器系统,根据价格范围或品牌等的选择,使某些div隐藏或显示。

当我使用过滤器时,它将移除顶部行的第2列,并使第二行的第4列移动到上一行。将第2列留在代码中,因此重新运行“高度/列”检查脚本将无法工作。

因此,我想要做的是使用我的filter(':nth-child(3n-2)')添加一个if语句,该语句将跳过隐藏在:nth-子选择中的所有div。

我知道我可以在我的filter();中使用一个函数,但是它对我来说是一个新函数,所以我不确定如何准确地使用它。

这是我的工作代码:

代码语言:javascript
复制
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实例

到目前为止,我正试图使用这样的方法:

代码语言:javascript
复制
$sections.filter(function() {
   return $(this).css('display') !== 'none';
}, ':nth-child(3n-2)')
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-18 11:58:45

to通过在调用:nth-child之前返回css属性使其正常工作。

代码语言:javascript
复制
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);
    });


}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18871393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档