Open In App

How to make Animated Click Effect using HTML CSS and JavaScript ?

Last Updated : 25 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will see how to make an Animated Click Effect using HTML CSS, and JavaScript. We generally see animations on modern websites that are smooth and give users a good experience.

Here, we will see when the user clicks on the button only then some animation would appear. The animation works after the button is clicked this is used in websites to confirm the user activity is done.

Prerequisites

Approach

  • Create the card structure using HTML tags, like <div>, <h1> for heading, <p> to display the word with corresponding classes and id's.
  • Add different styling properties in the CSS file using classes and elements that will define margin, padding, height, and border to the specific elements.
  • Give animation to the Heading when the page gets loaded.
  • Make function animateonce, and in the body of that function call setTimeout() which manipulates DOM when the user clicks a button and performs animation on the button.
  • Then, get the particular button element using getElementById and then add eventlistener after that call the function animateonce.

Example: This example will let you understand how we can make CLICK ANIMATION EFFECT using HTML, CSS, and JavaScript

HTML
<!-- Filename - index.html -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, 
            initial-scale=1.0">
    <title>CLICK ANIMATION EFFECT</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="container">

        <div class="card">
            <div class="content">
                <h1 class="heading-name">
                    GeeksforGeeks
                </h1>
                <p id="pid">
                    Click the button below to see
                    the Animation Effect
                </p>
                <div id="btn-parent">
                    <button class="btn" id="btn_id2">
                        Click Me
                    </button>
                </div>
            </div>
        </div>

    </div>
    <script src="script.js"></script>
</body>

</html>
CSS JavaScript

Output:


Next Article

Similar Reads