1

I built a blackjack game. Now I want the cards of the dealer, when they appear, to flip from back to the front. I built the keyframes in CSS but I can't apply it on the JS file.

JAVASCRIPT

function deal() {
    if (newgame == true) {
        var random = Math.floor((Math.random() * 13));
        var UserCards = document.getElementById('user');
        var card = document.createElement('img');
        card.setAttribute("width", 450);
        card.setAttribute("src", images[random]);
        UserCards.appendChild(card);
        UserCards.className ='myDIV';
        checkUserScore += cards[random];  
        if (checkUserScore > 21)
        {
            UserCards.appendChild(card);
            alert("you hit more than 21");
        }          
    }

EDIT: Did the OP leave out the function closing brace when pasting the code, or is that an actual error?

CSS

<style>
        .myDIV {
            margin: auto;
            border: 1px solid black;
            width: 500px;
            height: 500px;
            background-image:url(media/cards/UpsideDown.jpg);
            color: white;
            animation: mymove 5s infinite;
        }

        @keyframes mymove {
            50% {
                transform: rotate(360deg);
                background-image:url(media/cards/QC.jpg);
            }
        }
</style>
1
  • 3
    Please show your markup. Neither JS nor CSS mean anything without it. Commented Jun 4, 2021 at 13:56

1 Answer 1

1

Have you searched the web?

body {
  font-family: Arial, Helvetica, sans-serif;
}

.flip-card {
  background-color: transparent;
  width: 300px;
  height: 300px;
  perspective: 1000px;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}

.flip-card:hover .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.flip-card-front {
  background-color: #bbb;
  color: black;
}

.flip-card-back {
  background-color: #2980b9;
  color: white;
  transform: rotateY(180deg);
}
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">

<h1>Card Flip with Text</h1>
<h3>Hover over the image below:</h3>

<div class="flip-card">
  <div class="flip-card-inner">
    <div class="flip-card-front">
      <img src="img_avatar.png" alt="Avatar" style="width:300px;height:300px;">
    </div>
    <div class="flip-card-back">
      <h1>John Doe</h1>
      <p>Architect & Engineer</p>
      <p>We love that guy</p>
    </div>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

yes i did , i saw what you posted , i dont know how to make the card flip by it's own without clicking , i want it to flip after an image is appended child activaited

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.