250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Animation
- php
- 비전공 개발자
- button
- javascript
- 프론트엔드
- html5
- css3
- jQuery
- CSS
- iPhone
- IOS
- MAC
- iOS 개발자
- 자바스크립트
- keyframes
- HTML
- react
- 풀스택
- 비전공자
- ipad
- xcode
- 개발자
- front-end
- 백엔드
- SWIFT
- effect
- 애니메이션
- image
- hover
Archives
- Today
- Total
비전공자 개발일기
Flip a Coin 본문
728x90
SMALL
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FLIP A COIN</title>
<!--Google Fonts-->
<link href="https://fonts.googleapis.com/css2?family=Rubik:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<script defer src="main.js"></script>
</head>
<body>
<div class="container">
<div class="stats">
<p id="heads-count">Heads: 0</p>
<p id="tails-count">Tails: 0</p>
</div>
<div class="coin" id="coin">
<div class="heads">
<img src="https://i.postimg.cc/NFsp7c41/heads.png">
</div>
<div class="tails">
<img src="https://i.postimg.cc/0230rmLG/tails.png">
</div>
</div>
<div class="buttons">
<button id="flip-button">
Flip Coin
</button>
<button id="reset-button">
Reset
</button>
</div>
</div>
</body>
</html>
*{
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: "Rubik",sans-serif;
}
body{
height: 100%;
background: linear-gradient(
to right,
#575ce5 50%,
#f9fbfc 50%
) fixed;
}
.container{
background-color: #ffffff;
width: 400px;
padding: 50px;
position: absolute;
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
box-shadow: 15px 30px 35px rgba(0,0,0,0.1);
border-radius: 10px;
-webkit-perspective: 300px;
perspective: 300px;
}
.stats{
text-align: right;
color: #101020;
font-weight: 500;
line-height: 25px;
}
.coin{
height: 150px;
width: 150px;
position: relative;
margin: 50px auto;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.coin img{
width: 145px;
}
.heads,.tails{
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.tails{
transform: rotateX(180deg);
}
@keyframes spin-tails{
0%{
transform: rotateX(0);
}
100%{
transform: rotateX(1980deg);
}
}
@keyframes spin-heads{
0%{
transform: rotateX(0);
}
100%{
transform: rotateX(2160deg);
}
}
.buttons{
display: flex;
justify-content: space-between;
}
button{
width: 120px;
padding: 10px 0;
border: 2.5px solid #424ae0;
border-radius: 5px;
cursor: pointer;
}
#flip-button{
background-color: #424ae0;
color: #ffffff;
}
#flip-button:disabled{
background-color: #e1e0ee;
border-color: #e1e0ee;
color: #101020;
}
#reset-button{
background-color: #ffffff;
color: #424ae0;
}
let heads = 0;
let tails = 0;
let coin = document.querySelector(".coin");
let flipBtn = document.querySelector("#flip-button");
let resetBtn = document.querySelector("#reset-button");
flipBtn.addEventListener("click", () => {
let i = Math.floor(Math.random() * 2);
coin.style.animation = "none";
if (i) {
setTimeout(function () {
coin.style.animation = "spin-heads 3s forwards";
}, 100);
heads++;
} else {
setTimeout(function () {
coin.style.animation = "spin-tails 3s forwards";
}, 100);
tails++;
}
setTimeout(updateStats, 3000);
disableButton();
});
function updateStats() {
document.querySelector("#heads-count").textContent = `Heads: ${heads}`;
document.querySelector("#tails-count").textContent = `Tails: ${tails}`;
}
function disableButton() {
flipBtn.disabled = true;
setTimeout(function () {
flipBtn.disabled = false;
}, 3000);
}
resetBtn.addEventListener("click", () => {
coin.style.animation = "none";
heads = 0;
tails = 0;
updateStats();
});
728x90
LIST
'Javascript' 카테고리의 다른 글
Search Highlight Text (0) | 2022.11.29 |
---|---|
Blob Maker (0) | 2022.11.25 |
RGB - HEX Converter (0) | 2022.11.19 |
Palindrome Checker (0) | 2022.11.16 |
Temperature Convertor (0) | 2022.11.14 |