Pens

Material Ripple Wave Click Button

UI Component bởi acmatvjrus
Mở Studio
<div class="btn-stage">
  <button class="ripple-btn" id="rippleBtn">NHẤP THỬ NGAY</button>
</div>
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.ripple-btn {
  position: relative;
  background: #10a37a;
  color: #ffffff;
  border: none;
  padding: 16px 42px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1.5px;
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(16, 163, 122, 0.3);
  outline: none;
}
.ripple-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  transform: scale(0);
  animation: rippleAnim 0.6s linear;
  pointer-events: none;
}
@keyframes rippleAnim {
  to {
    transform: scale(4);
    opacity: 0;
  }
}
const btn = document.getElementById("rippleBtn");
btn.addEventListener("click", function (e) {
  const circle = document.createElement("span");
  circle.classList.add("ripple-circle");
  const rect = this.getBoundingClientRect();
  const d = Math.max(rect.width, rect.height);
  circle.style.width = circle.style.height = d + "px";
  circle.style.left = e.clientX - rect.left - d / 2 + "px";
  circle.style.top = e.clientY - rect.top - d / 2 + "px";
  this.appendChild(circle);
  setTimeout(() => circle.remove(), 600);
});
Đã sao chép vào bộ nhớ tạm!