Cursor · 14 of 22
Ripple Click
Water ripple effect on click
<div class="ripple-area" id="rippleArea">
<h2>Click Me</h2>
</div>
.ripple-area {
position: relative;
height: 240px;
display: flex;
align-items: center;
justify-content: center;
background: #12121a;
color: #f0f0f5;
overflow: hidden;
font-family: sans-serif;
}
.ripple-ring {
position: absolute;
border: 2px solid #7c5cff;
border-radius: 50%;
pointer-events: none;
transform: translate(-50%, -50%);
}
var area = document.getElementById('rippleArea');
var MAX_SIZE = 200; // px — ripple diameter at the end
var DURATION = 600; // ms
area.addEventListener('click', function (e) {
var rect = area.getBoundingClientRect();
var rip = document.createElement('div');
rip.className = 'ripple-ring';
rip.style.left = (e.clientX - rect.left) + 'px';
rip.style.top = (e.clientY - rect.top) + 'px';
area.appendChild(rip);
rip.animate([
{ width: '10px', height: '10px', opacity: 1 },
{ width: MAX_SIZE + 'px', height: MAX_SIZE + 'px', opacity: 0 }
], { duration: DURATION, easing: 'ease-out' }).onfinish = function () {
rip.remove();
};
});