jQuery同位素过滤问题

时间:2013-06-04 11:48:48

标签: jquery jquery-isotope

我正在使用jQuery Isotope过滤Portofolio部分

我的过滤器

      <div id="filters" class="portfolioSection">
        <ul>
          <li><a class="current" href="#" data-filter="*">All</a></li>
          <li><a href="#" data-filter="category-1">Category 1</a></li>
          <li><a href="#" data-filter="category-2">Category 2</a></li>
          <li><a href="#" data-filter="category-3">Category 3</a></li>
        </ul>
      </div>

内容部分

<div class="portfolioContent">
            <ul class="row">
              <li class="portfolio element category-1 category-2"><img src="img/project1.png">
                <div class="projectName">Project Name</div>
                <div class="projectCategory">Category 1</div>
              </li>
              <li class="portfolio element category-3"><img src="img/project2.png">
                <div class="projectName">Project Name</div>
                <div class="projectCategory">Category 1</div>
              </li>
              <li class="portfolio element category-3"><img src="img/project3.png">
                <div class="projectName">Project Name</div>
                <div class="projectCategory">Category 1</div>
              </li>
              <li class="portfolio element category-3"><img src="img/project4.png">
                <div class="projectName">Project Name</div>
                <div class="projectCategory">Category 1</div>
              </li>
              <li class="portfolio element category-1 category-3"><img src="img/project5.png">
                <div class="projectName">Project Name</div>
                <div class="projectCategory">Category 1</div>
              </li>
              <li class="portfolio element category-2"><img src="img/project6.png">
                <div class="projectName">Project Name</div>
                <div class="projectCategory">Category 1</div>
              </li>
              <li class="portfolio element category-1 category-2"><img src="img/project7.png">
                <div class="projectName">Project Name</div>
                <div class="projectCategory">Category 1</div>
              </li>
              <li class="portfolio element category-2"><img src="img/project8.png">
                <div class="projectName">Project Name</div>
                <div class="projectCategory">Category 1</div>
              </li>
            </ul>
          </div>

我的Jquery代码:

var $container = $('.portfolioContent');
// initialize isotope
$container.isotope({
  // options...
    itemSelector : '.portfolio',
  //layoutMode : 'fitRows'
});

// filter items when filter link is clicked
$('#filters a').click(function(){
  var selector = $(this).attr('data-filter');
  $container.isotope({ filter: selector });
  return false;
});

当我点击All之外的所有内容时,所有内容都会消失。 并且还缺少平滑过渡的效果。

链接:http://play.mink7.com/sophiance/点击查看部分

1 个答案:

答案 0 :(得分:5)

您的语法略有错误:

<li><a href="#" data-filter="category-1">Category 1</a></li>

应该是:

<li><a href="#" data-filter=".category-1">Category 1</a></li>

注意班级名称之前的.

来自Isotope documentation