<Button>Touch Me</Button>
@import url('https://fonts.googleapis.com/css?family=Montserrat:700');
$color: black;
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
position: fixed;
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background: white;
}
button {
position: relative;
display: block;
margin: 0 auto;
background: $color;
color: #fff;
text-align: center;
font-size: 16px;
font-family: "Montserrat";
font-weight: 700;
padding: 20px 45px;
letter-spacing: .25em;
text-transform: uppercase;
border: 0;
overflow: hidden;
border: 5px white solid;
cursor: pointer;
&:active,
&:visited,
&:focus {
outline: 0;
border: 0;
}
}
/* Ripple */
span {
width: 0;
height: 0;
border-radius: 50%;
background: rgba(255, 255, 255, 0.5);
transform: scale(0);
position: absolute;
opacity: 1;
}
.rippleAnimation {
animation: ripple .6s linear;
}
@keyframes ripple {
100% {
transform: scale(2);
opacity: 0;
}
}
View Compiled
let btn = document.querySelector('button');
function ripple(e) {
// Setup
let posX = this.offsetLeft;
let posY = this.offsetTop;
let buttonWidth = this.offsetWidth;
let buttonHeight = this.offsetHeight;
// Add the element
let ripple = document.createElement('span');
this.appendChild(ripple);
// Make it round!
if(buttonWidth >= buttonHeight) {
buttonHeight = buttonWidth;
} else {
buttonWidth = buttonHeight;
}
// Get the center of the element
var x = e.pageX - posX - buttonWidth / 2;
var y = e.pageY - posY - buttonHeight / 2;
ripple.style.width = `${buttonWidth}px`;
ripple.style.height = `${buttonHeight}px`;
ripple.style.top = `${y}px`;
ripple.style.left = `${x}px`;
ripple.classList.add('rippleAnimation');
setTimeout(() => {
this.removeChild(ripple);
}, 1000);
}
btn.addEventListener('click', ripple);
This Pen doesn't use any external CSS resources.