A Pen by Tobias Reich on CodePen.
Created
January 7, 2019 15:53
-
-
Save Tanvir82/bac805f96c4748a66d0f60431b58a780 to your computer and use it in GitHub Desktop.
Mouse movement button with border-radius
This file contains hidden or 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
<button class="button"> | |
<span>Hover me I'm awesome</span> | |
</button> |
This file contains hidden or 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
document.querySelector('.button').onmousemove = (e) => { | |
const x = e.pageX - e.target.offsetLeft | |
const y = e.pageY - e.target.offsetTop | |
e.target.style.setProperty('--x', `${ x }px`) | |
e.target.style.setProperty('--y', `${ y }px`) | |
} |
This file contains hidden or 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
body { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
min-height: 100vh; | |
background: white; | |
} | |
.button { | |
position: relative; | |
appearance: none; | |
background: #f72359; | |
padding: 1em 2em; | |
border: none; | |
color: white; | |
font-size: 1.2em; | |
cursor: pointer; | |
outline: none; | |
overflow: hidden; | |
border-radius: 100px; | |
span { | |
position: relative; | |
pointer-events: none; | |
} | |
&::before { | |
--size: 0; | |
content: ''; | |
position: absolute; | |
left: var(--x); | |
top: var(--y); | |
width: var(--size); | |
height: var(--size); | |
background: radial-gradient(circle closest-side, #4405f7, transparent); | |
transform: translate(-50%, -50%); | |
transition: width .2s ease, height .2s ease; | |
} | |
&:hover::before { | |
--size: 400px; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment