Revert flipping a DIV after clicking on another
Check out the link. If you click on a product, it will flip over and display some information. You can flip all products at a specific point in time.
I only want one product upside down. Every time someone clicks on a different product, I want the previous one to return to its original appearance.
html:
<div class="card effect__EFFECT">
<div class="card__front">
<span class="card__text">front</span>
</div>
<div class="card__back">
<span class="card__text">back</span>
</div>
</div>
Javascript:
(function() {
var cards = document.querySelectorAll(".card.effect__click");
for ( var i = 0, len = cards.length; i < len; i++ ) {
var card = cards[i];
clickListener( card );
}
function clickListener(card) {
card.addEventListener( "click", function() {
var c = this.classList;
c.contains("flipped") === true ? c.remove("flipped") : c.add("flipped");
});
}
})();
CSS:
.card.effect__click.flipped .card__front {
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.card.effect__click.flipped .card__back {
-webkit-transform: rotateY(0);
transform: rotateY(0);
}
+3
source to share
1 answer
Try removing the "flipped" class on the card on click.
function clickListener(card) {
card.addEventListener( "click", function() {
$('.card.effect__click').removeClass('flipped');
var c = this.classList;
c.contains("flipped") === true ? c.remove("flipped") : c.add("flipped");
});
}
+1
source to share