javascript - 同位素过滤器仅在数据过滤器 ="*"上进行过滤,其他过滤器隐藏所有内容

标签 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;
}

最佳答案

您需要使用选择器语法指定类名,即:data-filter属性中的.novo,但您忘记了.并且刚刚有了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

<小时/>

关于javascript - 同位素过滤器仅在数据过滤器 ="*"上进行过滤,其他过滤器隐藏所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22099761/

相关文章:

jquery - 如何删除所有图像并添加新的图像列表?

javascript - 基于自动图像检索系统生成自动链接(Freewall.js - 网格布局)

jquery - 使用 jQuery 组织 JSON 结果

javascript - 单击表格行以选择复选框并禁用/启用按钮 jquery

javascript - 使用网络 worker 进行大厅更新(也许还有聊天)?

jquery - 相同的 Div 在 Jquery 中称为错误

jQuery 在单击时循环遍历 sibling 的多个状态

javascript - Isotope.js 加载后显示放置在列中的项目

javascript - 未使用的 div 出现在 React 谷歌地图上,我无法设置它的样式

javascript - 复制多个 Td