jQuery:结合“可过滤的组合”和砌体布局

发布于 2024-08-22 00:05:07 字数 502 浏览 4 评论 0原文

我正在尝试结合“可过滤的投资组合”(http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-filterable-portfolio-with-jquery/) 与 Masonry 布局...所以我希望我的项目重新调整在我过滤它们之后,它们与砖石一起,但它们停留在砖石放置它们的位置...

这是我非常粗略的第一个网站草稿: http://waynetest.kilu.de/lula/ (工作显然正在进行中..;))

是否有可能结合两个js脚本?

多谢, 凯瑟琳娜

I'm trying to combine the "filterable portfolio" (http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-filterable-portfolio-with-jquery/) with the Masonry layout ... so I want my items to readjust with masonery after I filtered them, but they stay in the position where masonery put them...

here's my very rough first website draft: http://waynetest.kilu.de/lula/
(work obviously in progress..;))

Is there a possibility to combine both js-scripts?

thanks a lot,
katharina

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡莣 2024-08-29 00:05:07

您随时可以尝试 http://isotope.metafizzy.co/

You could always try http://isotope.metafizzy.co/

梦里南柯 2024-08-29 00:05:07

首先创建一个隐藏的div并将真实数据放入其中。在此示例中,我们将其称为#hidden。然后为主 Masonry 创建一个空白 div。我们称之为#masonry。因此,到目前为止,我们有这样的情况:

<div id="hidden"> ... CONTAINING THE ACTUAL DATA ... </div>
<div id="masonry"></div> <!-- which is a blank div -->

项目将通过其数据相关进行检测,因此不要忘记将所有过滤器作为项目的数据相关。例如:

<div class="work" data-rel="Template Design">CONTENT</div>

作为过滤器,创建一个如下所示的列表:

<ul id="port_filter">
    <li data-rel="all" class="active">All</li>
    <li data-rel="Graphic Design">Graphic Design</li>
    <li data-rel="Template Design">Template Design</li>
    <li data-rel="Programming">Programming</li>
</ul>

现在,以这种方式处理初始填充和过滤功能:

// Initial loading
var all = $('#hidden .work');
$('#masonry').html(all);
$('#masonry').masonry({
    itemSelector: '.work',
    columnWidth: 299
});

// Portfolio filtering
$('#port_filter li').click(function(){
    if($(this).hasClass('active')) {
        return;
    }
    else {
        $('#port_filter li').removeClass('active');
        var filter = $(this).attr('data-rel');
        $(this).addClass('active');
        if(filter == 'all') {
            $('#masonry').html(all);
            $('#masonry').masonry();
        }
        else {
            $('#masonry').html('').html(all);
            removed = null;
            var removed = $('#masonry .work[data-rel!="' + filter + '"]');
            removed.remove();
            $('#masonry').masonry();
        }
    }
});

此方法在 Masonry v4 上进行了测试,效果最好。

First create a hidden div and put the real data to it. In this example we call it #hidden. Then create a blank div for the main Masonry. We call it #masonry. So, we have something like this so far:

<div id="hidden"> ... CONTAINING THE ACTUAL DATA ... </div>
<div id="masonry"></div> <!-- which is a blank div -->

The items will be detected by their data-rel so don't forget to all the filters as data-rel to the items. E.g:

<div class="work" data-rel="Template Design">CONTENT</div>

As the filters, create a list like this:

<ul id="port_filter">
    <li data-rel="all" class="active">All</li>
    <li data-rel="Graphic Design">Graphic Design</li>
    <li data-rel="Template Design">Template Design</li>
    <li data-rel="Programming">Programming</li>
</ul>

Now, handle the initial filling and the filtering functions this way:

// Initial loading
var all = $('#hidden .work');
$('#masonry').html(all);
$('#masonry').masonry({
    itemSelector: '.work',
    columnWidth: 299
});

// Portfolio filtering
$('#port_filter li').click(function(){
    if($(this).hasClass('active')) {
        return;
    }
    else {
        $('#port_filter li').removeClass('active');
        var filter = $(this).attr('data-rel');
        $(this).addClass('active');
        if(filter == 'all') {
            $('#masonry').html(all);
            $('#masonry').masonry();
        }
        else {
            $('#masonry').html('').html(all);
            removed = null;
            var removed = $('#masonry .work[data-rel!="' + filter + '"]');
            removed.remove();
            $('#masonry').masonry();
        }
    }
});

This method is tested on Masonry v4 and the best.

音栖息无 2024-08-29 00:05:07

我也想要同样的东西,终于让它发挥作用了。

请参阅:http://jasondaydesign.com/masonry_demo/

希望这能满足您的需求。

I wanted the same thing and finally have it working.

See: http://jasondaydesign.com/masonry_demo/

Hopefully that works for your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文