Last active
January 26, 2019 20:07
-
-
Save dhilipkmr/568e20114a40cca44e020158180b55ec to your computer and use it in GitHub Desktop.
Show Ripple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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