Bootstrap flip card with css3 transform

Lorenzo picture Lorenzo · Jun 7, 2015 · Viewed 11.6k times · Source

I want to create a bootstrap flip card by using CSS3 transform. I did started from this working and basic example

However I wanted to modify it to have a fixed height card and some minor enhancement. In particular I needed to have the card flip when the user click on an icon I have created on the top right corner.

I have modified the code as you can see here.

The problem is that the card does not flip back to front after having flipped correctly to the back side.

Can anybody suggest any solution?

NOTE: the problem seems to be with the jquery code. Actually I have

$('div.flipControl').on('click', function () {
    $(this).closest('div[class="card"]').toggleClass('flipped');
});

But if I change it with

$('div.flipControl').on('click', function () {
    $(this).parent().parent().parent().toggleClass('flipped');
});

Everything works as expected.

Answer

vals picture vals · Jun 8, 2015

I think that it is much simpler using directly the CSS class selector

$('.flipControl').on('click', function(){
    $(this).closest('.card').toggleClass('flipped');

});

demo