Filtered Gallery for Portfolio重新排列以显示内联?

时间:2016-12-10 23:01:00

标签: jquery html portfolio

我正在使用Bootstrap的3列组合框架创建过滤的库。该产品组合过滤掉所有内容,但它不会重新排列div项目以显示内联,它只是删除不具有相同数据依赖项而不是删除然后重新排列的项目,以便在那里进行排序。项目之间没有空格。

这是我的代码:

$(function(){
    var selectedClass = "";
    $(".filter").click(function(){
        selectedClass = $(this).attr("data-rel"); 
        $(".work").fadeTo(100, 0.1);
        $(".portfolio-item").not("."+selectedClass).fadeOut().removeClass('scale');
        setTimeout(function(){
            $("."+selectedClass).fadeIn().addClass('scale').sort();
            $(".work").fadeTo(300, 1);
        }, 300); 
    });
});

我尝试添加.sort功能,但没有任何改变,所以我假设我把它放在错误的位置或需要更多的代码?

  HTML

        <section class="no-padding" id="portfolio">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h2 class="section-heading">Portfolio</h2>
                <h3 class="section-subheading text-muted">A showcase of my work.</h3>
                <div class="tabs">
                    <button class="btn filter" id="filt" href="" data-rel="all">ALL</button>
                    <button class="btn filter" id="filt" data-rel="web">Web Design</button>
                    <button class="btn filter" id="filt" data-rel="graphics">Graphic Design</button>
                    <button class="btn filter" id="filt" data-rel="branding">Branding</button>
                    <button class="btn filter" id="filt" data-rel="photography">Photography</button>
                    <button class="btn filter" id="filt" data-rel="motion">Motion Graphics</button>

                </div> 
                <br>
            </div>
    <div class="work">    
        <div class="row">
            <div class="col-md-4 portfolio-item web scale tile all">
                <a href="#">
                    <img class="img-responsive" src="http://placehold.it/700x400" alt="">
                </a>
                <h3>
                    <a href="#">Project Name</a>
                </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.</p>
            </div>
            <div class="col-md-4 portfolio-item graphics scale  tile all">
                <a href="#">
                    <img class="img-responsive" src="http://placehold.it/700x400" alt="">
                </a>
                <h3>
                    <a href="#">Project Name</a>
                </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.</p>
            </div>
            <div class="col-md-4 portfolio-item branding scale tile all">
                <a href="#">
                    <img class="img-responsive" src="http://placehold.it/700x400" alt="">
                </a>
                <h3>
                    <a href="#">Project Name</a>
                </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.</p>
            </div>
        </div>
    <!-- /.row -->

        <!-- Projects Row -->
        <div class="row">
            <div class="col-md-4 portfolio-item motion scale tile all">
                <a href="img/portfolio/fullsize/1.jpg">
                    <img class="img-responsive" src="http://placehold.it/700x400" alt="">
                </a>
                <h3>
                    <a href="#">Project Name</a>
                </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.</p>
            </div>
            <div class="col-md-4 portfolio-item motion scale tile all">
                <a href="#">
                    <img class="img-responsive" src="http://placehold.it/700x400" alt="">
                </a>
                <h3>
                    <a href="#">Project Name</a>
                </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.</p>
            </div>
            <div class="col-md-4 portfolio-item motion scale tile all">
                <a href="#">
                    <img class="img-responsive" src="http://placehold.it/700x400" alt="">
                </a>
                <h3>
                    <a href="#">Project Name</a>
                </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.</p>
            </div>
        </div>

        <!-- Projects Row -->
        <div class="row">
            <div class="col-md-4 portfolio-item photography scale tile all">
                <a href="#">
                    <img class="img-responsive" src="http://placehold.it/700x400" alt="">
                </a>
                <h3>
                    <a href="#">Project Name</a>
                </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.</p>
            </div>
            <div class="col-md-4 portfolio-item graphics scale tile all">
                <a href="#">
                    <img class="img-responsive" src="http://placehold.it/700x400" alt="">
                </a>
                <h3>
                    <a href="#">Project Name</a>
                </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.</p>
            </div>
            <div class="col-md-4 portfolio-item web scale tile all">
                <a href="#">
                    <img class="img-responsive" src="http://placehold.it/700x400" alt="">
                </a>
                <h3>
                    <a href="#">Project Name</a>
                </h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna varius vitae.</p>
            </div>
        </div>
    </div> <!--WORK-->
    <!-- /.row -->
    <hr>
        </div>
    </div>
</section>

1 个答案:

答案 0 :(得分:0)

当您点击作品的按钮时,它会隐藏所有内容,然后显示所选类别的项目。

示例:点击&#34; Web Desing&#34;显示第一个和最后一个项目。

如果我清楚地理解了这个问题......最后一个应该出现在第一个的右边......不在它之下。

那是因为它是&#34;囚犯&#34;它的<div class="row"> 在这个CodePen中,我只删除了HTML中的那些 这是我做出的唯一改变 它现在可以&#34;漂浮&#34;自由地放在前一个元素的右边。

这是理想的结果吗?