JSFiddle - React, Tailwind, and code Playground

by Maulik Anand

HTML

<div id="boxcard" align="center">
            <div id="card1"><img src="http://img6.uploadhouse.com/fileuploads/17699/17699263b01721074bf094aa3bc695aa19c8d573.png" class=""></div>
            <div id="card2"><img src="http://img9.uploadhouse.com/fileuploads/17699/176992615db99bb0fd652a2e6041388b2839a634.png" class=""></div>
            <div id="card3"><img src="http://icons.iconarchive.com/icons/reclusekc/kulo/96/Skull-1-icon.png"></div>

CSS

#boxcard {
    z-index: 1;
    display: table;
        margin: 0px auto;
    width: auto;
}

#boxcard div{
    float: left;
    width: 100;
    height: 120;
    margin: 5px;
    padding: 5px;
    border: 4px solid #EE872A;
    cursor: pointer;
    border-radius: 10px;
    box-shadow: 0 1px 5px rgba(0,0,0,.5);
  background: #B1B1B1;
    z-index: 2;
}
#boxcard > div:nth-child(6n+1) {
    clear: both;
}
#boxcard div img {
    /*display: none;*/
    border-radius: 10px;
    z-index: 3;
    -o-transition-duration:.5s;
    -moz-transition-duration:.5s;
    -webkit-transition-duration:.5s;
    transition-duration:.5s;
}

#boxcard div img.flip{
-o-transform: rotateY(180deg);
    -moz-transform: rotateY(180deg);
    -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
   display:inline-block;

}

JavaScript

$(document.getElementById("card1")).click(OpenCard);
$(document.getElementById("card2")).click(OpenCard);
$(document.getElementById("card3")).click(OpenCard);
function OpenCard() {
		var id = $(this).attr("id");
        var img = document.querySelector("#" + id + " img");
        img.classList.toggle("flip");

        if (ImgOpened == "") {
            BoxOpened = id;
            ImgOpened = $("#" + id + " img").attr("src");
        }
        else {
            CurrentOpened = $("#" + id + " img").attr("src");
            if (ImgOpened != CurrentOpened) {
                setTimeout(function() {
                    document.querySelector("#" + id + " img").classList.toggle("flip");
                    document.querySelector("#" + BoxOpened + " img").classList.toggle("flip");
                    BoxOpened = "";
                    ImgOpened = "";
                }, 400);
            } 
        }
    }