A Pen by Jonny Scholes on CodePen.
Created
April 21, 2024 13:26
-
-
Save Slinjez/ae9f6debeb1564b0685530925ac56c9c to your computer and use it in GitHub Desktop.
In/out of focus text effect
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
.focus | |
.focus--mask | |
.focus--mask-inner Focus | |
p.credits Inspired by #[a(href="https://dribbble.com/shots/2076176-Focus") this great shot] by @eldinheric. Best viewed in Chrome - FF gets a little sticky :( |
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
$componentSize: 179px; | |
$maskSize: 50px; | |
$speed: 1s; | |
$borderOffset: 8px; | |
$backgroundColor: #89cb66; | |
$animationProps: $speed linear infinite alternate; | |
@keyframes mask-move { | |
0% { | |
transform: translateX(0); | |
} | |
100% { | |
transform: translateX($componentSize - $maskSize); | |
} | |
} | |
@keyframes mask-inner-move { | |
0% { | |
transform: translateX(0); | |
} | |
100% { | |
transform: translateX(-($componentSize - $maskSize)); | |
} | |
} | |
*, | |
*:before, | |
*:after { | |
box-sizing: border-box; | |
} | |
body, | |
html { | |
height: 100%; | |
} | |
body { | |
padding: 0; | |
margin: 0; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
background: $backgroundColor; | |
font-family: Helvetica Neue, Helvetica, Arial, sans-serif; | |
} | |
.focus { | |
font-size: 3rem; | |
text-transform: uppercase; | |
color: white; | |
letter-spacing: .2rem; | |
line-height: 1; | |
position: relative; | |
width: $componentSize; | |
&:before { | |
content: 'Focus'; | |
filter: blur(3px); | |
} | |
&:after { | |
content: ''; | |
position: absolute; | |
width: $maskSize; | |
height: calc(100% + #{$borderOffset}); | |
top: -($borderOffset / 2); | |
left: 0; | |
border-top: 2px solid; | |
border-bottom: 2px solid; | |
animation: mask-move $animationProps; | |
} | |
&--mask { | |
overflow: hidden; | |
position: absolute; | |
width: $maskSize; | |
height: 100%; | |
top: 0; | |
left: 0; | |
background: $backgroundColor; | |
animation: mask-move $animationProps; | |
&-inner { | |
animation: mask-inner-move $animationProps; | |
} | |
} | |
} | |
.credits { | |
color: white; | |
position: absolute; | |
bottom: 0; | |
left: 50%; | |
transform: translateX(-50%); | |
font-weight: 200; | |
letter-spacing: 0.05rem; | |
font-style: italic; | |
text-align: center; | |
a { | |
color: white; | |
text-decoration: none; | |
font-weight: normal; | |
&:hover { | |
text-decoration: underline; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment