简体   繁体   English

如何使用jquery在Twitter bootstrap3中使用nav nav-pills过滤投资组合网格

[英]How to filter Portfolio grid with nav nav-pills in twitter bootstrap3 with jquery

I want to filter portfolio grid with nav nav-pills in bootstrap3 我想用bootstrap3中的nav nav-pills过滤投资组合网格

HTML: HTML:

    div class="row">
        <div class="col-lg-12">

<div class="centered-pills">
 <ul id="filterOptions" class="nav nav-pills">

   <li> <a href="#" class="all">All</a></li>

  <li><a href="#" class="latest">Latest</a></li>
  <li><a href="#" class="featured">Featured</a></li>
 <li><a href="#" class="trending">Trending</a></li>
 </ul>
</div>

<ul class="grid cs-style-6">
            <li class="item latest">
                <figure>
                    <a href="portfolio-item.html">
                        <img class="img-responsive img-portfolio img-hover" src="image/items/1.jpeg" alt=""></a>
                    <figcaption>
                        <h3>Hoodies</h3>
                        <span>ToughSkins</span>
                        <a href="portfolio-item.html" class="btn btn-default btn-md" role="button">Take a look</a>
                    </figcaption>
                </figure>
            </li>
            <li class="item featured">
                <figure>
                    <a href="portfolio-item.html">
                        <img class="img-responsive img-portfolio img-hover" src="image/items/1.jpeg" alt=""></a>
                    <figcaption>
                        <h3>Featured Camera</h3>
                        <span>Jacob Cummings</span>
                        <a href="portfolio-item.html" class="btn btn-default btn-md" role="button">Take a look</a>
                    </figcaption>
                </figure>
            </li>
            <li class="item trending">
                <figure>
                    <a href="portfolio-item.html">
                        <img class="img-responsive img-portfolio img-hover" src="image/items/1.jpeg" alt=""></a>
                    <figcaption>
                        <h3>Trending Camera</h3>
                        <span>Jacob Cummings</span>
                        <a href="portfolio-item.html" class="btn btn-default btn-md" role="button">Take a look</a>
                    </figcaption>
                </figure>
            </li>
            <li class="item latest">
                <figure>
                    <a href="portfolio-item.html">
                        <img class="img-responsive img-portfolio img-hover" src="image/items/1.jpeg" alt=""></a>
                    <figcaption>
                        <h3>Fleece Hoodies</h3>
                        <span>Jacob Cummings</span>
                        <a href="portfolio-item.html" class="btn btn-default btn-md" role="button">Take a look</a>
                    </figcaption>
                </figure>
            </li>
            <li class="item featured">
                <figure>
                    <a href="portfolio-item.html">
                        <img class="img-responsive img-portfolio img-hover" src="image/items/1.jpeg" alt=""></a>
                    <figcaption>
                        <h3>Featured Camera</h3>
                        <span>Jacob Cummings</span>
                        <a href="portfolio-item.html" class="btn btn-default btn-md" role="button">Take a look</a>
                    </figcaption>
                </figure>
            </li>
            <li class="item trending">
                <figure>
                    <a href="portfolio-item.html">
                        <img class="img-responsive img-portfolio img-hover" src="image/items/1.jpeg" alt=""></a>
                    <figcaption>
                        <h3>Trending Camera</h3>
                        <span>Jacob Cummings</span>
                        <a href="portfolio-item.html" class="btn btn-default btn-md" role="button">Take a look</a>
                    </figcaption>
                </figure>
            </li>


        </ul>   

How should i write jquery to filter it grid portfolio based on nag-pill selection? 我应该如何编写jquery以基于nag-pill选择过滤网格组合?

I have written jQuery but it is not working 我已经写了jQuery,但是没有用

I'm sure it is wrong 我肯定是错的

 $(document).ready(function(){

$('#filterOptions li a').click(function() {
// fetch the class of the clicked item
var ourClass = $(this).attr('class');

// reset the active class on all the buttons
$('#filterOptions li').removeClass('active');
// update the active state on our clicked button
$(this).parent().addClass('active');

if(ourClass == 'all') {
  // show all our items
  $('.grid cs-style-6').children('li.item').show();
}
else {
  // hide all elements that don't share ourClass
  $('.grid cs-style-6').children('li:not(.' + ourClass + ')').hide();
  // show all elements that do share ourClass
  $('.grid cs-style-6').children('li.' + ourClass).show();
   }
return false;
  });
});

Can some one please help me with this? 有人可以帮我吗?

// on click of a check the data attr and show li based on attr val  
$('#filterOptions li a').on('click', function (e) {
    e.preventDefault(); // 
    a = $(this).data('filter'); // finding the data value
    $('.grid li').fadeOut().promise().done(function () { // hiding all li
        $('.grid li.' + a).fadeIn(); // show only the class having the class == data attr
    });

    if ($(this).hasClass('all')) { // check if all is clicked 
        $('.grid li').fadeOut().promise().done(function () { // hiding all
            $('.grid li').fadeIn(); // showing all
        });
    }
});

// on document ready check if a has class active
if ($('#filterOptions li a').hasClass('active')) { // check if active class it there you 
    $('.grid li').fadeIn(); //
}

demo - http://jsfiddle.net/d9b8pLvw/1/ 演示-http: //jsfiddle.net/d9b8pLvw/1/

Note: I have added data-filter attribute for a tags and gave the values you and added active class for a tag with all class 注:我添加data-filter的属性, a标签,并给了值,您并添加active classa带有标签all class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM