Giter Site home page Giter Site logo

card-animation's Introduction

Card Animation

Preview

thumbnail

How To Use

Html

    <div class="container">
        <div class="card active" id="card-1">
            <div class="footer">
                <span class="number">1</span>
                <h4 class="title ">Lion</h4>
            </div>
        </div>
        <div class="card" id="card-2">
            <div class="footer">
                <span class="number">2</span>
                <h4 class="title">Dog</h4>
            </div>
        </div>
        <div class="card" id="card-3">
            <div class="footer">
                <span class="number">3</span>
                <h4 class="title">Parrot</h4>
            </div>
        </div>
        <div class="card" id="card-4">
            <div class="footer">
                <span class="number">4</span>
                <h4 class="title">Turtle</h4>
            </div>
        </div>
        <div class="card" id="card-5">
            <div class="footer">
                <span class="number">5</span>
                <h4 class="title">Cat</h4>
            </div>
        </div>
        <div class="card" id="card-6">
            <div class="footer">
                <span class="number">6</span>
                <h4 class="title">Owl</h4>
            </div>
        </div>
    </div>

Css

/* REBOOT */
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
}
/* BODY */
body {
    background-color: #000000;
    min-width: 40vw ;
}

/* CONTAINER */
.container {
    display: flex;
    width: 100%;
    height: 100vh;
    align-items: center;
    justify-content: center;
    background-color: #eeeeea;
}

/* CARD */
.card {
    display: flex;
    align-items: flex-end;
    height: 60vh;
    width: 80px;
    margin: 0 10px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 30px;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0px 10px 30px -5px rgba(0, 0, 0, 0.8);
    transition: .6s cubic-bezier(.28,-0.03,0,.99);
}
.card.active {
    width: 600px;
}

/* FOOTER */
.card .footer {
    display: flex;
    flex-wrap: nowrap;
    color: #eaeaee;
}

.card .footer .number {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin: 15px;
    font-size: 25px;
    font-weight: 700;
    background-color: #0F1035;
    color: #ffffff;
}

/* TITLE */
.footer .title {
    opacity: 0;
    font-size: 25px;
    font-weight: 700;
    transition: 0.5s ease-in;
    text-transform: uppercase;
    margin: auto;
}

.card.active .title {
    opacity: 1;
    transition: 2s;
}

/* ANIMATION */

@keyframes fadeOut {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}
@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

@media screen and (width <= 800px) {
    .card:nth-child(5),
    .card:nth-child(6) {
        animation: fadeOut 0.5s forwards;
        
    }
    .card.active {
        width: 500px;
    }

    .card .footer .number{
        width: 35px;
        height: 35px;
        margin-right: 10px !important;
        margin-left: 3px;
        right: 0;
        left: 0;
        font-size: 20px !important;
        font-weight: 500;
    }
    .footer .title {
        font-size: 20px !important;
        font-weight: 500;
    }
}
@media screen and (width > 800px) {
    .card:nth-child(5),
    .card:nth-child(6) {
        display: flex !important;
        animation: fadeIn 0.5s forwards;
    }
}

/* @CARD-BACKGROUND */

#card-1 {
    background-image: url(./img/lion.jpg);
}
#card-2 {
    background-image: url(./img/dog.jpg);
}
#card-3 {
    background-image: url(./img/parrot.jpg);
}
#card-4 {
    background-image: url(./img/turtle.jpg);
}
#card-5 {
    background-image: url(./img/cat.jpg);
}
#card-6 {
    background-image: url(./img/owl.jpg);
}

JavaScript

const cards = document.querySelectorAll('.card');
const fiveAndSixCards = document.querySelectorAll(".card:nth-child(5), .card:nth-child(6)");


function updateCardsVisibility() {
    let screenWidth = window.innerWidth;
    fiveAndSixCards.forEach(function(card) {
        card.addEventListener("animationend", () => {
            card.style.display = (screenWidth <= 800) ? 'none' : 'flex';
            }
        );
    });
}
window.addEventListener("DOMContentLoaded", updateCardsVisibility);
window.addEventListener("resize", updateCardsVisibility);

// ACTIVE CLASS
function removeActiveClass() {
    cards.forEach((card) => {
        card.classList.remove('active');
    })
}

cards.forEach((card) => {
    card.addEventListener('click', () => {
        removeActiveClass(card)
        card.classList.add('active');
    })
})

card-animation's People

Contributors

enesyuvarlan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.