Hello reader, I am simeydotme. Nice to meet you again in this free code sharing website. In this post I am going to explain about CSS Shimmer Button .
If you are new to this website, we recommend you to subscribe to our youtube channel and watch the videos. Ok lets dive into the code.
Images
These are the output images of the code. You can click on the image to enlarge it. also you can click the try it button to see the output.
Youtube Tutorial Video
If you are a visual learner and want to learn how to use this code, you can watch the video below.
and also this video contains the clear step by step explanation and the output of the code.
Source Code
This is the source code of the code. You can copy and paste the code to your editor.
console.log("Event Fired")
// inspired by Aaron Iker
// https://codepen.io/aaroniker/pen/PoOvoaY
// and Adam Argyle
// https://codepen.io/argyleink/details/abPvZJo
// uses custom properties, so will only work in Chromium Browsers.
let levels = [1, 4, 7];
let btn = document.querySelector("button");
let radios = document.querySelectorAll("[type=radio]");
let count = document.querySelector(".count");
let t = document.querySelector("textarea");
let previousWords = wordCount(t.value);
let previousLevel = 0;
let deltaUp = false;
count.innerHTML = levels.at(-1) + 1 - wordCount(t.value);
function wordCount(str) {
return str.trim().split(" ").length;
}
t.oninput = (e) => {
const str = t.value;
const words = wordCount(str);
let level = 0;
count.innerHTML = Math.max(levels.at(-1) + 1 - words,0);
btn.classList.add("disabled");
btn.classList.remove("level0");
btn.classList.remove("level1");
btn.classList.remove("level2");
btn.setAttribute("disabled", true);
addShine = () => {
if (previousLevel < level) {
btn.classList.remove("textShine");
window.requestAnimationFrame(() => {
btn.classList.add("textShine");
previousLevel = level;
});
} else {
previousLevel = level;
}
}
if (words > levels[2]) {
level = 3;
btn.removeAttribute("disabled");
btn.classList.remove("disabled");
btn.classList.remove("level0");
btn.classList.remove("level1");
btn.classList.add("level2");
addShine()
} else if (words > levels[1]) {
level = 2;
btn.removeAttribute("disabled");
btn.classList.remove("disabled");
btn.classList.remove("level0");
btn.classList.add("level1");
addShine()
} else if (words > levels[0]) {
level = 1;
btn.removeAttribute("disabled");
btn.classList.remove("disabled");
btn.classList.add("level0");
addShine()
} else {
level = 0;
btn.setAttribute("disabled", true);
btn.classList.add("disabled");
previousLevel = level;
}
previousWords = words;
};
radios.forEach((r) => {
r.onchange = (e) => {
btn.dataset.effect = e.currentTarget.value;
};
if( r.checked ) {
btn.dataset.effect = r.value;
}
});
And also you can click the try it button to see the output of the code in our web Code Playground.
You can also download the code to the zip format by clicking the download button. The download process is little bit complex, you need ti await for 10 seconds. after that you can download the code by clicking the generated download link.
Leave a Comment
You need to login first to comment.