Seeking assistance with creating a card that rotates upon clicking. The current setup is functional, however, I am aiming to utilize the onclick
event to append the 'is-flipped' class to the classlist of div.card. Upon inspecting the event through console log, the target appears as
<div class="card__face card__face--front">front</div>
while currentTarget remains null. Initially, I suspected the issue might be related to absolute positioning and attempted implementing z-index: 100 without success. Why is this occurring and what approach should be taken to select the .card div?
// var card = document.querySelector(".card");
// card.addEventListener("click", function () {
// card.classList.toggle("is-flipped");
// });
function handleCardClick(e) {
// e.stopPropagation();
console.log(e);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Poppins", sans-serif;
}
body {
font-family: sans-serif;
}
.wrapper {
width: 200px;
height: 260px;
border: 1px solid #ccc;
margin: 40px 0;
perspective: 600px;
}
.card {
width: 100%;
height: 100%;
transition: transform 1s;
transform-style: preserve-3d;
cursor: pointer;
position: relative;
z-index: 100;
}
.card.is-flipped {
transform: rotateY(180deg);
}
.card__face {
position: absolute;
width: 100%;
height: 100%;
line-height: 260px;
color: white;
text-align: center;
font-weight: bold;
font-size: 40px;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card__face--front {
background: red;
}
.card__face--back {
background: blue;
transform: rotateY(180deg);
}
<div class="wrapper">
<div class="card" onclick="handleCardClick(event)">
<div class="card__face card__face--front">front</div>
<div class="card__face card__face--back">back</div>
</div>
</div>
<div class="main" onclick="handleCardClick(event)">123456789</div>