Animated Download Button
Home
Snippets
Animated Download Button
HTML
CSS
JS
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"> <button id="download"> <span class="fill"></span> <span class="content"> <i class="fa-solid fa-download"></i> <span class="label">Download File</span> </span> </button>
* { box-sizing: border-box; } body { margin: 0; min-height: 100vh; display: grid; place-items: center; background: #101827; font-family: Arial, sans-serif; } button { position: relative; width: 190px; height: 54px; border: 0; border-radius: 13px; background: #635bff; color: white; font-size: 14px; font-weight: bold; cursor: pointer; overflow: hidden; box-shadow: 0 9px 25px #635bff35; transition: .3s; } .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: #817bff; } .content { position: relative; display: flex; justify-content: center; align-items: center; gap: 10px; height: 100%; } .content i { font-size: 17px; } button.done { background: #159b78; box-shadow: 0 9px 25px #159b7830; } button.done .fill { opacity: 0; } button.done i { animation: pop .4s ease; } @keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.3); } 100% { transform: scale(1); } }
const btn = document.querySelector("#download"); const fill = document.querySelector(".fill"); const label = document.querySelector(".label"); const icon = btn.querySelector("i"); let timer; btn.onclick = () => { if (timer) return; btn.classList.remove("done"); fill.style.width = "0%"; icon.className = "fa-solid fa-spinner fa-spin"; let progress = 0; label.textContent = "0%"; timer = setInterval(() => { progress += 2; fill.style.width = progress + "%"; label.textContent = progress + "%"; if (progress >= 100) { clearInterval(timer); timer = null; setTimeout(() => { btn.classList.add("done"); icon.className = "fa-solid fa-check"; label.textContent = "Downloaded!"; }, 250); } }, 35); };
Ad #1
Ad #2
Scroll to Top