Last active
May 7, 2019 19:12
-
-
Save miguelmota/736a05db65f39214a5db to your computer and use it in GitHub Desktop.
Sass glitch mixin
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
/* | |
@credit: http://css-tricks.com/glitch-effect-text-images-svg/ | |
(TEXT) PARAMS | |
================= | |
1. Namespace | |
2. Intensity | |
3. Text color | |
4. Background color (flat) | |
5. Highlight #1 color | |
6. Highlight #2 color | |
7. Width (px) | |
8. Height (px) | |
@example | |
@include textGlitch("example-one", 17, white, black, red, blue, 450, 115); | |
*/ | |
@mixin textGlitch($name, $intensity, $textColor, $background, $highlightColor1, $highlightColor2, $width, $height) { | |
color: $textColor; | |
position: relative; | |
$steps: $intensity; | |
// Ensure the @keyframes are generated at the root level | |
@at-root { | |
// We need two different ones | |
@for $i from 1 through 2 { | |
@keyframes #{$name}-anim-#{$i} { | |
@for $i from 0 through $steps { | |
#{percentage($i*(1/$steps))} { | |
clip: rect( | |
random($height)+px, | |
$width+px, | |
random($height)+px, | |
0 | |
); | |
} | |
} | |
} | |
} | |
} | |
&:before, | |
&:after { | |
content: attr(data-text); | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
background: $background; | |
clip: rect(0, 0, 0, 0); | |
} | |
&:after { | |
left: 2px; | |
text-shadow: -1px 0 $highlightColor1; | |
animation: #{$name}-anim-1 2s infinite linear alternate-reverse; | |
} | |
&:before { | |
left: -2px; | |
text-shadow: 2px 0 $highlightColor2; | |
animation: #{$name}-anim-2 3s infinite linear alternate-reverse; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment