Use Jquery Isotope to filter Fancybox gallery

妖精的绣舞 提交于 2020-01-17 06:00:23

问题


I'm trying to use Isotope to filter my gallery down to categories and then open up FancyBox and only have the filtered categories be presented in Fancybox.

Here is my code:

HTML

<div class="filters">
  <div class="ui-group">
    <div class="button-group js-radio-button-group" data-filter-group="color">
      <button class="button" data-filter="*">ALL</button>|
      <button class="button" data-filter=".wedding">WEDDINGS</button>|
      <button class="button" data-filter=".concert">CONCERT/SHOWS</button>|
      <button class="button" data-filter=".corporate">CORPORATE EVENTS</button>|
      <button class="button" data-filter=".church">CHURCH EVENTS</button>|
      <button class="button" data-filter=".political">POLITICAL EVENTS</button>|
      <button class="button" data-filter=".parties">PARTIES</button>
    </div>
  </div>
</div>
    </div>
    <!-- /.container -->
<div class="grid">
<div class="gutter-sizer"></div>
    <a class='fancybox' href='../images/picture-1' data-fancybox="gallery" data-fancybox-group='gallery' data-filter='church'>
        <div class="grid-item church"><img src="../images/picture-1"></div>
    </a>

    <a class='fancybox' href='../images/picture-2' data-fancybox="gallery" data-fancybox-group='gallery' data-filter='wedding'>
        <div class="grid-item wedding"><img src="../images/picture-2"></div>
    </a>

    <a class='fancybox' href='../images/picture-' data-fancybox="gallery" data-fancybox-group='gallery' data-filter='church'>
        <div class="grid-item church"><img  src="../images/picture-3"></div>
    </a>
</div>

JS

    $(".fancybox").fancybox({

    });
        $('#filters a').click(function(){
              var selector = $(this).attr('data-filter');
          $('#gallery').isotope({ filter: selector }, function(){
            if(selector == "*"){
             $(".fancybox").attr("data-fancybox-group", "gallery");
            } else{ 
             $(selector).find(".fancybox").attr("data-fancybox-group", selector);
            }
          });
          return false;
        });
}); // ready

回答1:


You can simply create custom click event to display visible items:

$('.fancybox').on('click', function() {
  var visibleLinks = $('.fancybox:visible');

  $.fancybox.open( visibleLinks, {}, visibleLinks.index( this ) );

  return false;
});

See full demo - http://codepen.io/fancyapps/pen/EZKYPN

(this demo uses v3, but it would be similar for v2, too)



来源:https://stackoverflow.com/questions/42589595/use-jquery-isotope-to-filter-fancybox-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!