Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rotation effect to cards #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function toggleSound(){

// unset image src when either card flip or show all cards
const unsetImgSource = (card) =>{
flip(card)
card.children[0].src="#"; // Removing image src so that it isn't visible through HTML
card.children[0].alt="card front face"; // Removing image alt so that it isn't visible through HTML
card.children[1].style.display="block";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hiding/unhiding the front pattern was temporary till this issue. Now after adding the rotation, there should be no need to hide/unhide it, as it should go backside.

so remove that

Expand Down Expand Up @@ -181,6 +182,10 @@ function toggleSound(){
flippedCards.length= 0;
}

function flip(card) {
card.classList.toggle("flip")
}

function flipCard(e, i){
const card = e.target

Expand All @@ -189,12 +194,13 @@ function toggleSound(){
return;

flippedCards.push(card)
flip(card)
setImgSource(card, i);

//when we have filled two cards check for the match
if(flippedCards.length === 2)
{
setTimeout(checkForMatch,100); // Adding a small delay, so that card gets enough time to render updated src before alert pops up
setTimeout(checkForMatch,1000); // Adding a small delay, so that card gets enough time to render updated src before alert pops up
}
}

Expand Down
7 changes: 7 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ header{
align-items:center;
background-color: rgba(255, 255, 255, 0.289);
padding: 10px 0px;
perspective: 1000px;
}

#restart-btn, .modal--btn{
Expand Down Expand Up @@ -135,6 +136,8 @@ header{
width: 24%;
position: relative;
background-color: white;
transform-style: preserve-3d;
transition: transform 1s;
}

.memory-card>img{
Expand All @@ -149,6 +152,7 @@ header{
object-fit: scale-down;
/* object-fit: cover; */
/* object-position: top center; */
transform: rotateY(180deg);

}
.front-face,.back-face{
Expand Down Expand Up @@ -203,3 +207,6 @@ header{
padding: 12px 30px;
}

.flip {
transform: rotateY(180deg);
}