Skip to content

Instantly share code, notes, and snippets.

@dhilipkmr
Last active January 26, 2019 20:07
Show Gist options
  • Save dhilipkmr/568e20114a40cca44e020158180b55ec to your computer and use it in GitHub Desktop.
Save dhilipkmr/568e20114a40cca44e020158180b55ec to your computer and use it in GitHub Desktop.
Show Ripple
.ripple .rippleContainer span {
transform: scale(0);
border-radius: 100%;
position: absolute;
opacity: 0.75;
background-color: #ffffff;
animation: ripple 850ms;
}
@keyframes ripple {
to {
opacity: 0;
transform: scale(2);
}
}
showRipple = (e) => {
const rippleContainer = e.currentTarget;
const size = rippleContainer.offsetWidth;
const pos = rippleContainer.getBoundingClientRect();
const x = e.pageX - pos.x - (size / 2);
const y = e.pageY - pos.y - (size / 2);
const spanStyles = { top: y + 'px', left: x + 'px', height: size + 'px', width: size + 'px' };
const count = this.state.count + 1;
this.setState({
spanStyles: {...this.state.spanStyles, [count] : spanStyles},
count: count
});
}
renderRippleSpan = () => {
const {showRipple = false, spanStyles = {}} = this.state;
const spanArray = Object.keys(spanStyles);
if (spanArray && spanArray.length > 0) {
return (
spanArray.map((key, index) => {
return <span key={'spanCount_' + index} className="" style={{ ...spanStyles[key]}}></span>
})
)
} else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment