Skip to content

Instantly share code, notes, and snippets.

@bushidocodes
Created September 1, 2017 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bushidocodes/8cd67d5c998e123d5ac7062536fe771c to your computer and use it in GitHub Desktop.
Save bushidocodes/8cd67d5c998e123d5ac7062536fe771c to your computer and use it in GitHub Desktop.
Saving Stuart's Expressive Text work for future reference.
// components/expressive-text.scss
@import '../variables.scss';
@import '../mixins.scss';
// Local Variables
$colors-default: $colors-datarange-bad-to-good;
$precision-default: 24;
$steps-default: gradient;
// Helpers
@mixin expressive-text(
$colors: $colors,
$precision: $precision,
$steps: $steps) {
&[data-value-ratio] {
background: -webkit-linear-gradient($colors);
background-clip: text;
-webkit-background-clip: text;
text-fill-color: transparent;
-webkit-text-fill-color: transparent;
background-size: 200em; // Any large-enough multiple of text size to appear solid
}
@if $steps == gradient {
@for $i from 0 through $precision {
&[data-value-ratio="#{$i}"] {
background-position-y: $i + %;
}
}
} @else {
@for $i from 0 through $precision {
$norm: floor($precision/$steps);
$frac: floor($i/$norm) * $norm;
&[data-value-ratio="#{$i}"] {
background-position-y: $frac * 1%;
}
}
}
}
// Styles
.exp-text {
@include expressive-text($colors: $colors-default, $precision: $precision-default, $steps: $steps-default);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment