0

I am currently working on a portfolio for an artist. I am using Masonry with Isotope to filter for specific kinds of paintigs. When the items are being clicked, it opens lightGallery: http://sachinchoolur.github.io/lightGallery/

Everything works fine so far, the problem is the following:

What I want to achieve is that, if you filter for nature paintings for example, only the nature paintings will be shown and if you click on one of the items it opens the gallery. But the problem is, that at the moment ALL images of ALL categories are been shown in the gallery of nature. So if you click through them, you also get images of the category 'people' for example.

I guess the aim there is to give the different categories different 'galleries'. But if the filter 'show all' is clicked, the user should also be able to click through all the images of all categories, so that the gallery is not ending when the category of the item being clicked 'ends'.

As Im not that good with javascript, I hope you may be able to help me a little bit and that you understand my problem ..

The Code HTML MARKUP

<div class="categories">
        <button data-filter="*">Alle</button>
        <button data-filter=".ship">Schiff</button>
        <button data-filter=".copop">CoPop</button>
        <button data-filter=".grey_bg">grey bg</button>
</div>

<div class="grid" id="lightgallery">
        <a class="grid__item copop" href="app/assets/img/co-pop.jpg">
          <img class="grid__item__img" src="app/assets/img/co-pop.jpg">
        </a>
        <a class="grid__item ship" href="app/assets/img/ship.jpg">
          <img class="grid__item__img" src="app/assets/img/ship.jpg">
        </a>
      <a class="grid__item copop" href="app/assets/img/co-pop.jpg">
        <img class="grid__item__img" src="app/assets/img/co-pop.jpg">
      </a>
      <a class="grid__item ship" href="app/assets/img/ship.jpg">
        <img class="grid__item__img" src="app/assets/img/ship.jpg">
      </a>
      <a class="grid__item copop" href="app/assets/img/co-pop.jpg">
        <img class="grid__item__img" src="app/assets/img/co-pop.jpg">
      </a>
      <a class="grid__item ship" href="app/assets/img/ship.jpg">
        <img class="grid__item__img" src="app/assets/img/ship.jpg">
      </a>
    </div>
</div>

JS initialize lightgallery

<script type="text/javascript">
      $(document).ready(function() {
          $("#lightgallery").lightGallery();
      });
  </script>

JS isotope

    (function($) {

$('#wrap').imagesLoaded(function() {

    $('.categories').on( 'click', 'button', function() {
        var filterValue = $(this).attr('data-filter');
        $grid.isotope({ filter: filterValue });
    });

    var $grid = $('.grid').isotope({
        itemSelector: '.grid__item',
        percentPosition: true,
        masonry: {
            columnWidth: '.grid__item'
        }
    })
});

So I guess I need to create several galleries and say in the code that only the items of that activated data-filter gallery will be shown when clicked. But maybe that would also work without creating extra multiple galleries? Because then the problem would maybe be, that when all items are active, only the ones in that specific gallery of the selected item will be shown in the lightGallery.

Thank you for your help in advance!

carlpoppa
  • 115
  • 1
  • 10

1 Answers1

-2

kindly check this pen to get what you need

$(document).ready(function() {
   var $gallery = $('#gallery');
   var $boxes = $('.revGallery-anchor');
   $boxes.hide(); 

   $gallery.imagesLoaded( {background: true}, function() {
      $boxes.fadeIn();

    $gallery.isotope({
     // options
     sortBy : 'original-order',
     layoutMode: 'fitRows',
     itemSelector: '.revGallery-anchor',
     stagger: 30,
    });
   }); 

    $('button').on( 'click', function() {
     var filterValue = $(this).attr('data-filter');
      $('#gallery').isotope({ filter: filterValue });
      $gallery.data('lightGallery').destroy(true);
       $gallery.lightGallery({
          selector: filterValue.replace('*','')
       });
   });
});

$(document).ready(function() {
         $("#gallery").lightGallery({
            
}); 
     });

//button active mode
$('.button').click(function(){
    $('.button').removeClass('is-checked');
    $(this).addClass('is-checked');
});


//CSS Gram Filters on Mouse enter
$("#gallery a .nak-gallery-poster").addClass("inkwell");

$("#gallery a").on({
  mouseenter : function() {
      $(this).find(".nak-gallery-poster").removeClass("inkwell").addClass("walden");
  },
  mouseleave : function() {
      $(this).find(".nak-gallery-poster").removeClass("walden").addClass("inkwell");
  }
}); 
.revGallery-anchor, .gal-overlay, .nak-gallery-poster{
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
}


.revGallery-anchor{
  overflow: hidden;
  position: relative;
  width: calc(100% / 5);
  display: block;
  float: left;
  border: 5px solid #e9e9e9;
}

.gal-overlay{
  display: block;
  width: 100%;
  height: 100%;
  background: rgba(27,27,27, 0.6);
  position: absolute;
  top: 0;
  left: 0;
  transition: background .4s ease;
  -webkit-transition: background .4s ease;
}
  
.revGallery-anchor:hover .gal-overlay{
  background: rgba(27,27,27, 0);
}

.nak-gallery {
  display: block;
  width: 100%;
  position: relative;
  margin-top: 30px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
}

.nak-gallery-poster{
  padding-bottom:100%;
  transform-origin: 50% 50%;
  -webkit-transform-origin: 50% 50%;
  -ms-transform-origin: 50% 50%;
  transform: scale(1, 1);
  -webkit-transform: scale(1, 1);
  -ms-transform: scale(1, 1);
  transition: all .4s ease;
  -webkit-transition: all .4s ease;
}

.revGallery-anchor:hover .nak-gallery-poster{
  transform: scale(1.1, 1.1);
  -webkit-transform: scale(1.1, 1.1);
  -ms-transform: scale(1.1, 1.1);
}

.img-responsive{
  display:none;
}

.button{
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  -webkit-transition: all .4s ease;
  -moz-transition: all .4s ease;
  -o-transition: all .4s ease;
  transition: all .4s ease;
  width: 200px;
  height: 48px;
  border: 1px solid rgba(0,169,157,1);
  background-color: rgba(0,169,157,1);
  border-radius: 2px;
  color: #fff;
  letter-spacing: 2px;
}

.button:hover {
  background-color: #363636;
  text-shadow: 0 1px hsla(0, 0%, 100%, 0.5);
  color: #fff;
}

.button:active,
.button.is-checked {
  background-color: #28F;
}

.button.is-checked {
  color: white;
  text-shadow: 0 -1px hsla(0, 0%, 0%, 0.8);
}

.button:active {
  box-shadow: inset 0 1px 10px hsla(0, 0%, 0%, 0.8);
}


.revGallery-anchor-width1{
  width: 40%
}

.revGallery-anchor-width2{
  width: 30%
}

.revGallery-anchor-width3{
  width: 20%
}

.nak-gallery-height1{
  padding-bottom: 400px
}

.nak-gallery-height2{
  padding-bottom: 300px
}

.nak-gallery-height3{
  padding-bottom: 200px
}

.preloader{
  display: none;
}

.preloaderStyle{
  background: red;
  width: 100%;
  height: 100px;
}
<button type="button" class="button is-checked" data-filter="">ALL</button>
<button type="button" class="button" data-filter=".design">DESIGN</button>
<button type="button" class="button" data-filter=".branding">BRANDING</button>

<div class="nak-gallery nlg1" id="gallery">
  <a href="http://unsplash.com/photos/GYNxcQvBNzA/download" class="revGallery-anchor design">
    <img class="img-responsive" src="http://unsplash.com/photos/GYNxcQvBNzA/download">
    <div style="overflow:hidden">
      <div class="nak-gallery-poster" style="background-image:url('http://unsplash.com/photos/GYNxcQvBNzA/download');background-size:cover;background-repeat:no-repeat;background-position:center center;display: block;width: 100%;height: 0;"></div>
    </div>
    <div class="gal-overlay">
      <div class="photo"></div>
    </div>
  </a> 
  <a href="https://www.youtube.com/watch?v=Io0fBr1XBUA" class="revGallery-anchor branding">
    <img class="img-responsive" src="http://unsplash.com/photos/ssAcdlJRsI4/download">
    <div style="overflow:hidden">
      <div class="nak-gallery-poster" style="background-image:url('http://unsplash.com/photos/ssAcdlJRsI4/download');background-size:cover;background-repeat:no-repeat;background-position:center center;display: block;width: 100%;height: 0;"></div>
    </div>
    <div class="gal-overlay">
      <div class="photo"></div>
    </div>
  </a> 
  <a href="http://unsplash.com/photos/EKIyHUrUHWU/download" class="revGallery-anchor design">
    <img class="img-responsive" src="http://unsplash.com/photos/EKIyHUrUHWU/download">
    <div style="overflow:hidden">
      <div class="nak-gallery-poster" style="background-image:url('http://unsplash.com/photos/EKIyHUrUHWU/download');background-size:cover;background-repeat:no-repeat;background-position:center center;display: block;width: 100%;height: 0;"></div>
    </div>
    <div class="gal-overlay">
      <div class="photo"></div>
    </div>
  </a> 
  <a href="http://unsplash.com/photos/CFi7_hCXecU/download" class="revGallery-anchor branding">
    <img class="img-responsive" src="http://unsplash.com/photos/CFi7_hCXecU/download">
    <div style="overflow:hidden">
      <div class="nak-gallery-poster" style="background-image:url('http://unsplash.com/photos/CFi7_hCXecU/download');background-size:cover;background-repeat:no-repeat;background-position:center center;display: block;width: 100%;height: 0;"></div>
    </div>
    <div class="gal-overlay">
      <div class="photo"></div>
    </div>
  </a>
  <a href="http://unsplash.com/photos/cFplR9ZGnAk/download" class="revGallery-anchor design">
    <img class="img-responsive" src="http://unsplash.com/photos/cFplR9ZGnAk/download">
    <div style="overflow:hidden">
      <div class="nak-gallery-poster" style="background-image:url('http://unsplash.com/photos/cFplR9ZGnAk/download');background-size:cover;background-repeat:no-repeat;background-position:center center;display: block;width: 100%;height: 0;"></div>
    </div>
    <div class="gal-overlay">
      <div class="photo"></div>
    </div>
  </a> 
</div>

https://codepen.io/kannan3024/pen/YWoQgq

Ayham Atiyah
  • 1
  • 1
  • 1
  • Thank you for this code snippet, which might provide some limited short-term help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its long-term value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made. – Toby Speight Jul 27 '18 at 13:13