SOURCE

console 命令行工具 X clear

                    
>
console
const button = document.querySelector('button.ripple');


button.addEventListener('click', e => {
    const x = e.clientX;
    const y = e.clientY;

    const buttonTop = e.target.offsetTop;
    const buttonLeft = e.target.offsetLeft;

    const left = x - buttonLeft;
    const top = y - buttonTop;

    const circle = document.createElement('span');
    circle.className = 'circle';
    circle.style.top = top + 'px';
    circle.style.left = left + 'px';
    button.appendChild(circle);
    setTimeout(() => circle.remove(), 500)

})


<button class="ripple">Click Me</button>
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
}

button {
    position: relative;
    background-color: #1976d2;
    color: #fff;
    font: 14px bold;
    border: 0;
    border-radius: 5px;
    text-transform: uppercase;
    letter-spacing: 2px;
    padding: 20px 30px;
    cursor: pointer;
    box-shadow: 0px 5px 5px -3px rgba(0, 0, 0, 0.3);
    transition: all 0.3s;
    /* 重要 */
    overflow: hidden;
}

button:hover {
    box-shadow: 0px 8px 8px -3px rgba(0, 0, 0, 0.3), 4px 0 8px -3px rgba(0, 0, 0, 0.3), -4px 0px 8px -3px rgba(0, 0, 0, 0.3);
}

button .circle {
    position: absolute;
    background-color: #fff;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    /* 圆圈一开始大小为0 */
    transform: translate(-50%, -50%) scale(0);
    animation: scale 0.5s ease-out;
    opacity: 0.5;
}

@keyframes scale {
    to {
        transform: translate(-50%, -50%) scale(3);
        opacity: 0;
    }
}