同位素仅在data-filter =“*”上过滤,每个人都隐藏一切

时间:2014-02-28 15:53:24

标签: javascript jquery jquery-isotope

我的同位素过滤器仅适用于应显示所有容器的过滤器链接,当单击每个其他过滤器时,所有容器都被隐藏。

这是工作fiddle

以下是代码:

HTML

<div class="isotope-nav">
    <ul class="isotope-filters">
        <li><a class="#" data-filter="*">All posts</a>
        </li>           
        <li><a class="novo isotope-link" href="#" data-filter="novo">Novo</a>
        </li>
        <li><a class="uncategorized isotope-link" href="#" data-filter="uncategorized">Uncategorized</a>
        </li>
        <li><a class="vesti isotope-link" href="#" data-filter="vesti">Vesti</a>
        </li>
    </ul>
</div>
<!-- end .isotope-nav -->
<div class="isotope-container">
    <div class="col-lg-3 post-container uncategorized ">
        <div class="post-header">   
              <a href="#" class="isotope-link uncategorized">Uncategorized</a> 
        </div>
        <!-- end .post-header -->

    </div>
    <!-- end .post-container -->
    <div class="col-lg-3 post-container uncategorized ">
       <div class="post-header">    
             <a href="#" class="isotope-link uncategorized">Uncategorized</a> 
       </div>
       <!-- end .post-header -->

    </div>
    <!-- end .post-container -->
    <div class="col-lg-3 post-container novo novo vesti ">
        <div class="post-header">   
              <a href="#" class="isotope-link novo">Novo</a>  <a href="#" class="isotope-link vesti">Vesti</a> 
        </div>
        <!-- end .post-header -->
    </div>
    <!-- end .post-container -->
    <div class="col-lg-3 post-container novo novo vesti ">
        <div class="post-header">   
         <a href="#" class="isotope-link novo">Novo</a>  <a href="#" class="isotope-link vesti">Vesti</a> 
        </div>
        <!-- end .post-header -->
    </div>
     <!-- end .post-container -->
    <div class="col-lg-3 post-container vesti ">
        <div class="post-header">   <a href="#" class="isotope-link vesti">Vesti</a> 
        </div>
    <!-- end .post-header -->
    </div>
    <!-- end .post-container -->
    <div class="col-lg-3 post-container novo novo vesti ">
        <div class="post-header">   
            <a href="#" class="isotope-link novo">Novo</a>  <a href="#" class="isotope-link vesti">Vesti</a> 
        </div>
        <!-- end .post-header -->
    </div>
    <!-- end .post-container -->
    <div class="col-lg-3 post-container novo novo vesti ">
        <div class="post-header">   
            <a href="#" class="isotope-link novo">Novo</a>  <a href="#" class="isotope-link vesti">Vesti</a> 
        </div>
        <!-- end .post-header -->
    </div>
          <!-- end .post-container -->
    <div class="col-lg-3 post-container novo novo vesti ">
        <div class="post-header">   
           <a href="#" class="isotope-link novo">Novo</a>  <a href="#" class="isotope-link vesti">Vesti</a> 
        </div>
        <!-- end .post-header -->
    </div>
           <!-- end .post-container -->
    <div class="col-lg-3 post-container novo novo vesti ">
        <div class="post-header">   
            <a href="#" class="isotope-link novo">Novo</a>  <a href="#" class="isotope-link vesti">Vesti</a> 
        </div>
        <!-- end .post-header -->

    </div>
    <!-- end .post-container -->
    <div class="col-lg-3 post-container novo novo vesti ">
        <div class="post-header">   
             <a href="#" class="isotope-link novo">Novo</a>  <a href="#" class="isotope-link vesti">Vesti</a> 
        </div>
            <!-- end .post-header -->
    </div>
    <!-- end .post-container -->
</div>
<!-- end .isotope-container -->

JS

jQuery(document).ready(function($){
//isotope
$container = $('.isotope-container');
$container.isotope({
    itemSelector : '.post-container',
    layoutMode : 'masonry'
});

$('.isotope-filters li a').click(function(){
    var selector = $(this).attr('data-filter');
    $container.isotope({ filter: selector });
    return false;
});
});

CSS

/**** Isotope filtering ****/
.isotope-item {
  z-index: 2;
}
.isotope-hidden.isotope-item {
  pointer-events: none;
  z-index: 1;
}

1 个答案:

答案 0 :(得分:1)

您需要使用选择器语法指定类名,即.novo属性中的data-filter,但您忘记了.并且只有novo。其他人一样。

将您的data-filter值更改为.novo.uncategorized.vesti,如下所示:

<div class="isotope-nav">
    <ul class="isotope-filters">
        <li><a class="#" data-filter="*">All posts</a>
        </li>           
        <li><a class="novo isotope-link" href="#" data-filter=".novo">Novo</a>
        </li>
        <li><a class="uncategorized isotope-link" href="#" data-filter=".uncategorized">Uncategorized</a>
        </li>
        <li><a class="vesti isotope-link" href="#" data-filter=".vesti">Vesti</a>
        </li>
    </ul>
</div>

DEMO - 更新data-filter