hide images and release the space.
I have a lightbox gallery. Everything is fine but I wanted to make it filterable.
I used a tutorial and ended up with this code:
HTML:
- <ul id="filter">
<li class="current"><a href="#">All</a></li>
<li><a href="#">Kitchens</a></li>
<li><a href="#">Bathrooms</a></li>
<li><a href="#">CAD</a></li>
</ul>
<script>
jQuery(function () {
jQuery.thumbGrid.transitions.slideLeft = {in: {x:"0%", opacity:0}, out: {x:"-100%", opacity:0}};
jQuery.thumbGrid.transitions.slideRight = {in: {x:"0%", opacity:0}, out: {x:"100%", opacity:0}};
jQuery("[data-thumbgrid]").thumbGrid();
});
</script>
-
- <section class="content">
- <div id="thumbGrid" class=""
- data-thumbgrid="true"
- data-effect="slideInverse"
- data-delay="60"
- data-timing="800"
- data-pagination="6"
- data-galleryeffectnext="slideLeft"
- data-galleryeffectprev="slideRight"
- data-cover="true">
- <img src="img/LR/01.jpg" class="kitchens" alt="img04" data-highres="img/HR/01.jpg" data-captio\
- n="text1"/>
- <img src="img/LR/02.jpg" class="kitchens" alt="img02" data-highres="img/HR/02.jpg" />
- <img src="img/LR/03.jpg" class="bathrooms" alt="img01" data-highres="img/HR/03.jpg" data-capti\
- on="text2"/>
- <img src="img/LR/04.jpg" class="cad" alt="img03" data-highres="img/HR/04.jpg" data-caption="text3"/>
- </div>
- </section>
jquery:
-
$(document).ready(function(){
$('#filter a').click(function() {
$(this).css('outline','none');
$('#filter li.current').removeClass('current');
$(this).parent().addClass('current');
var filterVal = $(this).text().toLowerCase().replace(' ','-');
if(filterVal == 'all') {
$('#thumbGrid img.hidden').fadeIn('slow').removeClass('hidden');
} else {
$('#thumbGrid img').each(function() {
if(!$(this).hasClass(filterVal)) {
$(this).fadeOut('normal').addClass('hidden');
} else {
$(this).fadeIn('slow').removeClass('hidden');
}
});
}
return false;
});
});
Also tried hide():
-
- $(document).ready(function(){
- $('#filter a').click(function() {
- $(this).css('outline','none');
- $('#filter li.current').removeClass('current');
- $(this).parent().addClass('current');
- var filterVal = $(this).text().toLowerCase().replace(' ','-');
- if(filterVal == 'all') {
- $('#thumbGrid img.hidden').removeClass('hidden').css('display', 'block');
- } else {
- $('#thumbGrid img').each(function() {
- if(!$(this).hasClass(filterVal)) {
- $(this).addClass('hidden').css('display', 'none');
- } else {
- $(this).removeClass('hidden').css('display', 'block');
- }
- });
- }
- return false;
- });
- });
In both cases, when I click on the categories they appear/disappear as intended. The only problem is that when an img gets hidden, there's still a gray container occupying the space. How can I free the space that a hidden img would normally occupy?
Thank you