Created
April 7, 2020 21:11
-
-
Save GravenilvecTV/953b87aeed237221ed5d1457fdb5b90f to your computer and use it in GitHub Desktop.
Correction TP JOUR 19/30 - HTML/CSS/JS - Bonneteau
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<!-- Tete de la page qui contient les métadonnées --> | |
<head> | |
<title>Jeu du bonneteau</title> | |
<!-- lier la page html avec la feuille de styles css --> | |
<link rel="stylesheet" type="text/css" href="css/styles.css"> | |
</head> | |
<!-- Corp de la page --> | |
<body> | |
<div class="container"> | |
<h1 class="titre">Bonneteau</h1> | |
<h3 class="slogan">La carte rouge gagne et les cartes noires perdent</h3> | |
<!-- toutes les cartes --> | |
<div class="cards"> | |
<div class="card" onclick="flip(event)"> | |
<!-- image de la carte rouge --> | |
<div class="front"> | |
<img class="card-img" src="images/black.png" width="200"> | |
</div> | |
<div class="back"></div> | |
</div> | |
<div class="card" onclick="flip(event)"> | |
<!-- image de la carte rouge --> | |
<div class="front"> | |
<img class="card-img" src="images/black.png" width="200"> | |
</div> | |
<div class="back"></div> | |
</div> | |
<div class="card" onclick="flip(event)"> | |
<!-- image de la carte rouge --> | |
<div class="front"> | |
<img class="card-img" src="images/black.png" width="200"> | |
</div> | |
<div class="back"></div> | |
</div> | |
</div> | |
<!-- un bouton generer --> | |
<button id="btn">Générer</button> | |
</div> | |
<!-- script javascript --> | |
<script src="js/script.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// recuperer le bouton avec l'id "btn" | |
let btn = document.getElementById('btn') | |
btn.addEventListener('click', shuffle) | |
let redcard = 0; | |
shuffle() | |
function shuffle() { | |
let allcards = document.getElementsByClassName("card-img"); | |
allcards[redcard].setAttribute('src', "images/black.png") | |
let random = Math.floor(Math.random() * allcards.length); // un nombre au hasard | |
let card = allcards[random]; | |
card.setAttribute('src', "images/red.png"); | |
redcard = random | |
} | |
function flip(event){ | |
let element = event.currentTarget; | |
if (element.className === "card"){ | |
if(element.style.transform == "rotateY(180deg)"){ | |
element.style.transform = "rotateY(0deg)"; | |
} | |
else{ | |
element.style.transform = "rotateY(180deg)"; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: #483D8B; | |
color: white; | |
margin: 20px; | |
line-height: 2px; | |
} | |
div { | |
width: 100%; | |
height: 100%; | |
} | |
div.container { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
flex-direction: column; | |
} | |
h1.titre { | |
font-size: 100px; | |
} | |
h3.slogan { | |
font-size: 45px; | |
} | |
div.cards { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
width: 100%; | |
height: 100%; | |
margin: 5%; | |
perspective: 1000px; | |
} | |
div.card { | |
transition: 1s; | |
width: 200px; | |
height: 300px; | |
margin: 10px; | |
transform-style: preserve-3d; | |
} | |
.front, .back { | |
position: absolute; | |
backface-visibility: hidden; | |
height: 300px; | |
} | |
.front { | |
background: url(../images/black.png) no-repeat; | |
background-size: 200px; | |
width: 200px; | |
transform: rotateY(180deg); | |
} | |
.back { | |
background: url(../images/dos.png); | |
background-size: 200px; | |
width: 200px; | |
} | |
button#btn { | |
font-size: 50px; | |
width: 100%; | |
} | |
.back:hover { | |
transition: 0.3s; | |
box-shadow: 0px 0px 20px 3px #000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment