【问题标题】:jQuery isotope with checkboxes and slider filters带有复选框和滑块过滤器的 jQuery 同位素
【发布时间】:2016-02-17 17:51:14
【问题描述】:

我用 jQuery isotope 和各种过滤器创建了一个页面。这是简化的 JSFiddle:

https://jsfiddle.net/itzuki87/21kfqhop/17/

如您所见,有 3 个过滤器:2 个复选框和 1 个范围滑块。如果单独使用所有过滤器都可以很好地工作,但是当我将它们组合使用时,它只适用于最后使用的过滤器。 这是因为我在使用范围滑块时使用“.show-me”类,而在使用复选框时使用其他类。

范围滑块:

$("#range").ionRangeSlider({
        hide_min_max: true,
        keyboard: true,
        min: 0,
        max: 150,
        from: 20,
        to: 110,
        type: 'double',
        step: 1,
        prefix: "€",
        grid: true,
        onChange: function(data) {
            $(".grid-item").each(function(){
            price = parseInt($(this).find(".price").text(), 10);
            if (data.from <= price && data.to >= price) {
                $(this).addClass('show-me');
            }
            else {
                $(this).removeClass('show-me');
            }
            });
            $container.isotope({
             itemSelector: '.grid-item',
             filter: '.show-me'
         });
        }
});

复选框:

$checkboxes.on('change', function(){
    filters = [];       
    $checkboxes.filter(':checked').each(function(){
        filters.push(this.value);
    });     

    filters = filters.join('');
    $container.isotope({
        filter: filters
    });     

});

如何才能使两种类型的过滤器同步工作?谢谢。

【问题讨论】:

    标签: javascript jquery jquery-isotope


    【解决方案1】:

    我自己解决了。我只是添加了

    $(".grid-item").addClass("show-me");
    filters.push(".show-me");
    

    一开始,

    filters.push(".show-me");
    

    在复选框功能中,我更改了滑块功能

    filter: filters
    

    所以每个项目的开头都有“show-me”类,如果数字不对应,则使用范围滑块将其删除。

    编辑后的JSfiddle是https://jsfiddle.net/21kfqhop/23/

    【讨论】:

    • 我确信我没有完整了解这到底是为了什么,但在你的例子中,如果你从滑块开始,所有的框都会消失,在我看来这是错误的,因为用户应该是能够使用任何过滤器来缩小框的选择范围。
    • 谢谢,我决定在开头添加filters = filters.join('')。现在 JSFiddle 应该没问题了。
    【解决方案2】:

    您基于旧版本的同位素创建了您的示例

    http://isotope.metafizzy.co/v1/demos/combination-filters.html

    版本之间以及如何组合过滤器存在差异:

    V1:.red 或 .tall,您可以传入两者的过滤器选择器:.red.tall

    V2:.red 或 .tall,您可以传入两者的过滤器选择器:.red、.tall

    filters = filters.join(', ');
    

    请查看http://codepen.io/desandro/pen/JGKyrY,我相信您将能够自己解决剩下的问题。

    【讨论】:

    • 如果我将 filters = filters.join(' '); 更改为 filters = filters.join(', '); 我会看到添加参数的复选框。我想要复选框缩小参数,这就是我创建的。我的脚本:Big + Yellow 仅返回大黄色框。我的脚本与您发布的更改:Big + Yellow 返回所有大框 + 所有黄色框,这不是我想要的。我的问题出在其他地方,即操作滑块和复选框,让我可以进一步缩小范围。
    猜你喜欢
    • 2013-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    相关资源
    最近更新 更多