gazrobur
gazrobur

Reputation: 141

How to add active class in Isotope js?

My filter is working great, but I could not figure it out how can I add an active class to the current block, (I get filter from database (especially its an id)), Is it possible to add the selected filter to an active class? If it is, then please help me out. Thanks.

<ul class="year" >
   <?php foreach($galery as $gal) : ?>
       <li> <a class="btn btn-default <?php echo $gal->id; ?>" data-filter=".<?php echo $gal->id;?>"><?php echo $gal->name; ?></a></li>
   <?php endforeach; ?>
</ul>


<script>

var $spcl = $('.spcl');

$spcl.isotope({
    itemSelector: '.item',
    layoutMode: 'fitRows',
    filter: '.1',
    masonry: {
        columnWidth: 70
    }
});

$('.year').on('click', 'a', function() {
    var selector = $(this).data('filter');

    $spcl.isotope({
        filter: selector
    });
});

});
</script>

Upvotes: 1

Views: 1946

Answers (1)

gazrobur
gazrobur

Reputation: 141

Finally I got the answer, so I would like to share it with you: I think its understandable.

 <ul class="year" >
   <?php foreach($galeria_kategoria as $gal) : ?>
       <li class="button-group"> <a class="<?php if($gal->id == 1) {echo 'is-checked';} ?> button btn btn-default <?php echo $gal->id; ?>" data-filter=".<?php echo $gal->id;?>"><?php echo $gal->name; ?></a></li>
    <?php endforeach; ?>
 </ul>


<script>
 $(function() {

$('.year').on('click', 'a', function() {


$('.button-group').find('.is-checked').removeClass('is-checked');
$( this ).addClass('is-checked');

    var selector = $(this).data('filter');

    $spcl.isotope({
        filter: selector
    });
});

});
</script>

Thanks

Upvotes: 4

Related Questions