A Pen by manan jain on CodePen.
Created
January 17, 2022 16:02
-
-
Save mananjain31/69e9298f4a3ac39918e3a9fab1ad1b2c to your computer and use it in GitHub Desktop.
ripple button
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
<div id='root'> | |
<button class="btn">Click</button> | |
</div> |
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
// function Root() | |
// { | |
// return <h1> Hello Peter </h1>; | |
// } | |
// ReactDOM.render(<Root/>, document.getElementById('root')); | |
window.addEventListener('load', ()=>{ | |
document.querySelectorAll('.btn').forEach(btn => btn.addEventListener('mousedown', ev => { | |
ev.target.childNodes.forEach(child => child.className==="rippleSpan" && child.remove()) | |
const child = document.createElement('span'); | |
child.className = "rippleSpan"; | |
child.style.position = "absolute"; | |
child.style.top = ev.clientY + 'px'; | |
child.style.left = ev.clientX + 'px'; | |
ev.target.appendChild(child); | |
})); | |
}); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script> |
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
.btn { | |
all : unset; | |
background : black; | |
font-size : 2rem; | |
padding : 10px 20px; | |
position : relative; | |
overflow : hidden; | |
letter-spacing : 3px; | |
color: white; | |
border-radius : 10px; | |
} | |
.rippleSpan{ | |
position : absolute; | |
background : white; | |
transform : translate(-50%, -50%); | |
pointer-events : none; | |
border-radius : 50%; | |
animation : ripple 4s linear 1; | |
} | |
@keyframes ripple { | |
0% { | |
width : 0; | |
height : 0; | |
opacity: 0.5; | |
} | |
40% { | |
width : 1000%; | |
height : 1000%; | |
opacity: 0.2; | |
} | |
100% { | |
width : 1000%; | |
height : 1000%; | |
opacity: 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment