我有一个脚本,在3列中使用一些浮动的div,从1行的3列获得最大的高度,并使所有的3 div都具有相同的高度。然后,它对每一行重复它,脚本工作很好,但是我已经在JQuery中构建了一个定制的过滤器系统,根据价格范围或品牌等的选择,使某些div隐藏或显示。
当我使用过滤器时,它将移除顶部行的第2列,并使第二行的第4列移动到上一行。将第2列留在代码中,因此重新运行“高度/列”检查脚本将无法工作。
因此,我想要做的是使用我的filter(':nth-child(3n-2)')添加一个if语句,该语句将跳过隐藏在:nth-子选择中的所有div。
我知道我可以在我的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)')发布于 2013-09-18 11:58:45
to通过在调用: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);
});
}https://stackoverflow.com/questions/18871393
复制相似问题