ํด๋น ํ์ด์ง ๊ฒ์ ์ฝ๋ ๋ฆฌ๋ทฐ
์ ๋ก์ด - ์นด๋ ๋ค์ง๊ธฐ ๊ฒ์ ์ฐธ๊ณ .
.card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.card.flipped .card-inner {
transform: rotateY(180deg);
}
.card-front,
.card-back {
border: 1px solid #585858;
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.card-back {
transform: rotateY(180deg);
}
http://uxuiz.cafe24.com/wp/archives/1212 : ๊ฐ๊ฐ์ css ๊ธฐ๋ฅ์ ๋ํ ์ค๋ช
let cardWidth = 4;
let cardHeight = 3;
function cardSet(cardWidth, cardHeight) {
clickFlag = false;
for (let i = 0; i < cardWidth * cardHeight; i += 1) {
let card = document.createElement('div');
card.className = 'card';
let cardInner = document.createElement('div');
cardInner.className = 'card-inner';
let cardFront = document.createElement('div');
cardFront.className = 'card-front';
let cardBack = document.createElement('div');
cardBack.className = 'card-back';
cardBack.style.backgroundColor = cardColor[i];
cardInner.appendChild(cardFront);
cardInner.appendChild(cardBack);
card.appendChild(cardInner);
๊ฐ๊ฐ์ card div ์์ inner์ด ๋ค์ด๊ฐ๊ณ front, back์ด ๋ณ๋ ฌ์ ์ผ๋ก ๋ค์ด๊ฐ๊ฒ ํ๋ค. ๊ทธ๋ฆฌ๊ณ for๋ฌธ์ผ๋ก 12๊ฐ์ ์นด๋๊ฐ ์์ฑ๋๋๋ก ํ๋ค.
(function (c) {
card.addEventListener('click', function () {
if (clickFlag && !matchedCard.includes(c)) {
c.classList.toggle('flipped');
clickedCard.push(c);
if (clickedCard.length === 2) {
if (
clickedCard[0].querySelector('.card-back').style
.backgroundColor ===
clickedCard[1].querySelector('.card-back').style.backgroundColor
) {
matchedCard.push(clickedCard[0]);
matchedCard.push(clickedCard[1]);
clickedCard = [];
if (matchedCard.length === cardWidth * cardHeight) {
let gameFinish = new Date();
alert(
`Congratulations๐ Time record: ${parseInt(
(gameFinish - gameStart) / 1000
)} seconds`
);
document.querySelector('#gameTable').innerHTML = '';
cardColorset = colorPool.slice();
cardColor = [];
matchedCard = [];
gameStart = null;
shuffle();
cardSet(cardWidth, cardHeight);
}
}
eventlistener๋ฅผ ์ฆ์์คํํจ์ function(c)
๋ก ๊ฐ์ธ์ ํด๋ก์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค.