Demo:
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.
- 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>
<progress>
, is the element that has a linear gradient background.
- 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);
}
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%;
}
.start-download
when clicked on button element, is added.
- 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);
Done! That's it, I'd like to know your opinion 🙋🏻❤️🔥.
.
.
More Tutorials:
.
Top comments (0)