Heart Beat Animation using HTML, CSS and JAVASCRIPT with heart-beat sound effect in Background.

 

Heart Beat Animation



                                                   Following is simple web development program

 that will animate a image by CSS  using Transform scale property of CSS.

 There will be background music in result ; As you press START button the heart

 image will animate as well background music will be played. See this

 awesome program you will like it.😀


Program Source code :-


<!DOCTYPE html>
<html lang="en">
<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>My Heart Beat Animation Project</title>
    <style type="text/css">
    *{
        margin0;
        padding0;
        box-sizingborder-box;
    }
    main{
        width90%;
        displaygrid;
        margin4rem auto;
        grid-template-rows:40vw;
        grid-template-columns70% 30%;
    }
    .content{
        displayflex;
        justify-contentcenter;
        align-itemscenter;
    }
    .content img{
        width50%;
        height60%;
    }

    button{
        width70%;
        height5rem;
        margin5rem auto;
        outlinenone;
        border.2rem solid #001;
        border-radius3rem;
        background:cyan;
        colorred;
        font-weight:800;
        font-family:Georgia;
        font-size2rem;
        cursorpointer;
    }

    button:hover{
        background-colorred;
        colorcyan;
    }

    audio{
        displaynone;
    }

    .animate{
        filterdrop-shadow(-15px -15px 18px #000);
        animation: beat 1s linear infinite;
    }

    @keyframes beat{
        0% {
        transformscale(1);
    }
    20% {
        transformscale(1);
    }
    40% {
        transformscale(1.4);
    }
    60% {
        transformscale(1.2);
    }
    80% {
        transformscale(1.4);
    }
    100% {
        transformscale(1);
    }
 }
    </style>
</head>
<body>
    <main>
        <div class="content">
            <img src="heart.png" alt="Heart Image">
        </div>
        <div class="btns">
            <button type="submit" id="btn1">START</button>
            <button type="submit" id="btn2">STOP</button>
            <audio src="heartbeat.mp3" controls loop></audio>
        </div>
    </main>
</body>
<script>

    b1 = document.getElementById('btn1');

    b2 = document.getElementById('btn2');

    i = document.querySelector('img');

    a = document.querySelector('audio');

    const st = () =>{
        a.play();
        i.classList.add('animate');
    };

    const sp = () =>{
        a.pause();
        i.classList.remove('animate');
    };


    b1.addEventListener("click",st);

    b2.addEventListener("click",sp);

</script>
</html>


OUTPUT : -





( NOTE : - While executing program you have to replace links of images , audio's  or video's in this program by your links. So take care of it ! )