Back
A step-by-step guide to building a visually impressive button with a halo glow and ripple feedback to captivate your users.
<button class="glow-button" onclick="createRipple(event)">Click Me!</button>
box-shadow property, which gives the button its glowing effect.
.glow-button {
position: relative;
padding: 10px 20px;
font-size: 16px;
color: #ffffff;
background-color: #03a9f4;
border: none;
border-radius: 25px;
cursor: pointer;
box-shadow: 0 0 10px 0 #03a9f4;
overflow: hidden;
transition: box-shadow 0.3s, transform 0.3s;
}
.glow-button:hover {
box-shadow: 0 0 20px 0px #03a9f4;
transform: scale(1.05);
}
.glow-button:active {
transform: scale(0.95);
}
For the ripple effect, a span element is dynamically added when the button is clicked. This ripple element is styled to start small and expand over time.
.glow-button .ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.7);
transform: scale(0);
animation: ripple 0.6s linear;
}
@keyframes ripple {
to {
transform: scale(4);
opacity: 0;
}
}
span element on each click, determining its position based on where you click the button, and animating it for visual feedback.
function createRipple(event) {
const button = event.currentTarget;
const circle = document.createElement("span");
const diameter = Math.max(button.clientWidth, button.clientHeight);
const radius = diameter / 2;
circle.style.width = circle.style.height = `${diameter}px`;
circle.style.left = `${event.clientX - button.offsetLeft - radius}px`;
circle.style.top = `${event.clientY - button.offsetTop - radius}px`;
circle.classList.add("ripple");
const ripple = button.getElementsByClassName("ripple")[0];
if (ripple) {
ripple.remove();
}
button.appendChild(circle);
}
background-color and box-shadow color to reflect different themes or branding guidelines.aria-label to the button for better screen reader support.em or rem for padding and font size.<button class="glow-button" onclick="createRipple(event)">Click Me!</button>
<script>
function createRipple(event) {
const button = event.currentTarget;
const circle = document.createElement("span");
const diameter = Math.max(button.clientWidth, button.clientHeight);
const radius = diameter / 2;
circle.style.width = circle.style.height = `${diameter}px`;
circle.style.left = `${event.clientX - button.offsetLeft - radius}px`;
circle.style.top = `${event.clientY - button.offsetTop - radius}px`;
circle.classList.add("ripple");
const ripple = button.getElementsByClassName("ripple")[0];
if (ripple) {
ripple.remove();
}
button.appendChild(circle);
}
</script>
<style>
.glow-button {
position: relative;
padding: 10px 20px;
font-size: 16px;
color: #ffffff;
background-color: #03a9f4;
border: none;
border-radius: 25px;
cursor: pointer;
box-shadow: 0 0 10px 0 #03a9f4;
overflow: hidden;
transition: box-shadow 0.3s, transform 0.3s;
}
.glow-button:hover {
box-shadow: 0 0 20px 0px #03a9f4;
transform: scale(1.05);
}
.glow-button:active {
transform: scale(0.95);
}
.glow-button .ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.7);
transform: scale(0);
animation: ripple 0.6s linear;
}
@keyframes ripple {
to {
transform: scale(4);
opacity: 0;
}
}
</style>
Thank you for reading this article.
Comments
No comments yet. Be the first to comment!