I have a container, with an unknown amount of cards in (ranging from 3 to 8).
| -- -- -- |
| CARD CARD CARD |
| -- -- -- |
And when one is clicked, all others disappear and the card clicked needs to move to the left. For example, if the middle card is clicked:
Cards disappear
| -- |
| CARD |
| -- |
Card moves to left (with an animation)
| -- |
| CARD |
| -- |
The cards are able to disappear but I feel my solution isn't great. I cannot move the card to the left.
Here's my solution for the hiding of the cards:
cards.forEach(card => {
card.addEventListener('click', () => {
cards.forEach(card2 => {
if(card2 != card){
card2.style.animation = 'fadeOut 0.2s linear forwards';
}
})
})
})
But I am very unsure how to move the card. Here's the css for the card container and card itself.
.cards{
height: 100%;
width: 100%;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 50px;
position: relative;
}
.card{
height: 100%;
width: 100%;
position: relative;
}
Is this possible with a css animation?