DEV Community

Cover image for Download Button: Interaction Animation Effects
Mohammad Sahragard
Mohammad Sahragard

Posted on

3 1

Download Button: Interaction Animation Effects

Demo:

Image description

If you don't feel like reading the text, see: https://youtu.be/GqeuTyft0kE

Description:
This is a cool effect and animation for download buttons. Useful and without empty lines, let's count, there are 60 lines. I hope you like it ❤️✌🏻.

Technologies Used:

  • HTML
  • CSS
  • Javascript

Now, let's go.

  1. At the earliest step, write the HTML codes:
    <div class="container">
        <button class="button">
            <div class="progress"></div>
            <span class="value">Download</span>
        </button>
    </div>
Enter fullscreen mode Exit fullscreen mode

<progress>, is the element that has a linear gradient background.

  1. Ok, let's write the CSS codes: (part 1)
.container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #23232f;
}

.button {
    all: unset;
    height: 50px;
    width: 120px;
    text-align: center;
    background-color: dodgerblue;
    color: #fff;
    border-radius: 5px;
    outline: 2px solid royalblue;
    outline-offset: 5px;
    transition: 0.4s;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.button:active {
    transform: scale(0.9);
}
Enter fullscreen mode Exit fullscreen mode

Now, Part 2:

.progress {
    position: absolute;
    inset: -20px 0 0 0;
    background-image: linear-gradient(to top, royalblue, deeppink);
    clip-path: polygon(0 0, 50% 20%, 100% 0, 100% 100%, 0 100%);
}
.value {
    position: relative;
}


.button.start-download {
    width: 50px;
    border-radius: 50%;
}
Enter fullscreen mode Exit fullscreen mode

.start-download when clicked on button element, is added.

  1. Well, now it's time for JavaScript:
const $ = document;
const query = queryItem => $.querySelector (queryItem);

// ------- data
const button = query ('.button');
const progress = query ('.progress');
const value = query ('.value');
let percent = 0;

// ------- function's
const startDownload = () => {
    const intervalItem = setInterval (() => {
        button.removeEventListener ('click', startDownload);
        percent++;

        button.classList.add ('start-download');
        progress.style.inset = `${percent}% 0 0 0`;
        value.innerHTML = `${percent}%`;

        if (percent === 100) {
            clearInterval(intervalItem);
            percent = 0;
            button.classList.remove('start-download');
            progress.style.inset = '-20px 0 0 0';
            value.innerHTML = 'Download';
            button.addEventListener('click', startDownload);
        }
    }, 30);
}

// ------ event's
button.addEventListener('click', startDownload);
Enter fullscreen mode Exit fullscreen mode

Done! That's it, I'd like to know your opinion 🙋🏻❤️🔥.

.

.

More Tutorials:

.

Follow Me In:

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay