Skip to content

Instantly share code, notes, and snippets.

@CodeMyUI
Created April 4, 2017 23:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeMyUI/c45a2964c9eb5054237f67e567903af8 to your computer and use it in GitHub Desktop.
Save CodeMyUI/c45a2964c9eb5054237f67e567903af8 to your computer and use it in GitHub Desktop.
In/out of focus text effect
.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 :(
$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