How to add a flip card effect in a memory campaign?

Stefano Rossi -

What is a flip card effect?

A flip card effect is an animation that flips a card from front to back (or vice versa) when the user clicks on it.

Enregistrementdelecran2024-07-08a15.14.34-ezgif.com-video-to-gif-converter.gif

 

How can I create this effect in my memory campaign?

Here are the steps to add a flip card effect using CSS and JavaScript:

Step 1: Use the Following CSS to style the cards and create the flip effect

Add the following CSS code in the CSS tab of the look and feel step.

/* Flip cards */

.card {
perspective: 1000px;
cursor: pointer;
box-shadow: none !important;
}
.content_img {
transform-style: preserve-3d;
transition: transform 0.5s;
}
.content_photo::before {
transform: rotateY(0deg);
}
.card.flipped .content_photo::before {
transform: rotateY(180deg);
}
.card.flipped .content_img {
transform: rotateY(180deg);
}
.card.flipped .content_photo img {
transform: rotateY(180deg);
}

 

Step 2: Add JavaScript to manipulate the cards

Finally, use JavaScript code to add the logic that flips the cards when they are clicked:

In the tag library, you can create a new "Tag name":

flip_cards_effect.

Then, add the JavaScript code in the body section.

<script> 
document.querySelectorAll('.card').forEach(card => {
card.addEventListener('click', function() {
this.classList.toggle('flipped');
});
});
</script>

By following these steps, you can easily add a flip card effect to your memory game, enhancing the user experience with a visually appealing animation.

Was this article helpful?

Can’t find the answer you need?

Send us a question and connect with an expert to get personal assistance.

Contact support

Vous ne trouvez pas les réponses que vous cherchez ?

Nous sommes là pour vous aider. Envoyez-nous une demande en direct !

Contacter le support
helpcenter experts