Created
June 9, 2016 21:36
-
-
Save kmck/c0176adac84cf5e1ff20b7ff3eca726c to your computer and use it in GitHub Desktop.
SCSS mixin to flatten a color against another color
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
// ## matte | |
// | |
// Calculate the color created by flattened the input color against a base color with an opacity | |
// | |
// @param {Color} $color: foreground color | |
// @param {Color} [$matte]: background color (or `transparent`) to matte the foreground against | |
// @param {Number} [$opacity]: mixing opacity of the foreground color, analogous to layer opacity | |
// in an image editor | |
// @return {Color} the matted color | |
// | |
@function matte($color, $matte: #ffffff, $opacity: 1) { | |
@if ($matte == transparent) { | |
@return rgba($color, opacity($color) * $opacity); | |
} @else { | |
@return mix(rgba($color, 1), rgba($matte, 1), 100 * opacity($color) * $opacity); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment