Download Button: Interaction Animation Effects
Tags: javascript, css, tutorial, beginners
Published: 2022-09-08 22:42:41

### Demo:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yihoqr4uckk7gv8mja5e.gif)
###### 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:
```HTML
    <div class="container">
        <button class="button">
            <div class="progress"></div>
            <span class="value">Download</span>
        </button>
    </div>
```
`<progress>`, is the element that has a linear gradient background.

2. Ok, let's write the CSS codes: (part 1)
```CSS
.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);
}
```

Now, Part 2:
```CSS
.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%;
}
```
`.start-download` when clicked on button element, is added.

3. Well, now it's time for JavaScript:

```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);
```
Done! That's it, I'd like to know your opinion 🙋🏻❤️🔥.

.

.

### More Tutorials:
- [Responsive Profile Page Using HTML and CSS](https://t.co/aMYyLNZsdZ)

.

### Follow Me In:
- [YouTube](https://www.youtube.com/user/https://www.youtube.com/user/https://www.youtube.com/channel/UCmlrWX41qiXEv6QNMzivxIw)
- [Instagram](https://instagram.com/MohammadSahragard)
- [GitHub](https://github.com/MohammadSahragrad)
- [Twitter](https://twitter.com/MammadSahragard)
- [LinkedIn](https://linkedin.com/in/MohammadSahragard)