0

I am having trouble getting my filtered table to change views at the same time. You can see it here in this jsfiddle. Ignore the overlapping text for now.

What I want to do is have it change to compact or full view when the button is pressed once. This somehow works when it is the button is clicked twice.. which isn't correct.

Any ideas? I am not great at jquery but I can get things to work

See fiddle and functions at bottom.

  var $timeBlock = $('.timeBlock'),
      $checkboxes = $('#filters input');

  $timeBlock.isotope({
    itemSelector: '.item'
  });

  $checkboxes.change(function(){
    var filters = [];
    // get checked checkboxes values
    $checkboxes.filter(':checked').each(function(){
      filters.push( this.value );
    });
    // ['.red', '.blue'] -> '.red, .blue'
    filters = filters.join(', ');
    $timeBlock.isotope({ filter: filters });
  });

  $('#shuffle').click(function(){
    $timeBlock.isotope('shuffle');
  });

  var $items = $timeBlock.children();

  $("#isotope-reset").click(function(){
      reset();
});


$('#compact').click(function () {
    $('.item').animate({width: "30%"}, 500);
    $('.item').animate({height: "35px"}, 500);
    reset();

});


$('#full').click(function () {
    $('.item').animate({width: "455px"}, 500);
    $('.item').animate({height: "80px"}, 500);
    reset();


});

function reset() {
    $('input[type=checkbox]').attr('checked',false);
    $timeBlock.isotope({
        filter: '*'
    });
}
3
  • what browser you have? Your fiddle is working on my Chrome 41.0.2 Commented Mar 25, 2015 at 17:59
  • Chrome. I may not have been clear. Click the full view button. It will do something... Then click it again and it will do what it should do on the first click. Same with compact (it starts in compact.) Commented Mar 25, 2015 at 18:07
  • Anyone have any idea? Commented Apr 2, 2015 at 13:59

1 Answer 1

1

you need to put functions into the queue.

click events do a queue, if animation is completed then run next. Look at documentation on callback complete

$(document).on('click', '#compact', function () {
    $('.item').animate({width: "30%"}, 500, function() {
        $('.item').animate({height: "35px"}, 500, function() {
            $(this).resetItems();
        });
    });
});


$(document).on('click', '#full', function () {
    $('.item').animate({width: "455px"}, 500, function() {
        $('.item').animate({height: "80px"}, 500, function() {
            $(this).resetItems();
        });
    });
});

event reset items, if you use jquery then register that functions into the jquery. It is not necessary but give to you good advantages of jquery

$.fn.resetItems = function() {
    $('input[type=checkbox]').attr('checked',false);
    $timeBlock.isotope({
        filter: '*'
    });
}

JSFIDDLE

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the information. I was not familiar with this. It does seem very slow on switching between the two but at at least it performing the full animation.
yes but optimalize is sometimes needed. But i am glad it will help to you move step go on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.