Skip to content

Instantly share code, notes, and snippets.

@jdudek

jdudek/_blending.scss Secret

Created Sep 16, 2016
Embed
What would you like to do?
@function blend-transparent($foreground, $background) {
// https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
$fg-opacity: opacity($foreground);
$bg-opacity: opacity($background);
$opacity: $fg-opacity + $bg-opacity * (1.0 - $fg-opacity);
$factor: $bg-opacity * (1.0 - $fg-opacity);
$red: (red($foreground) * $fg-opacity + red($background) * $factor) / $opacity;
$green: (green($foreground) * $fg-opacity + green($background) * $factor) / $opacity;
$blue: (blue($foreground) * $fg-opacity + blue($background) * $factor) / $opacity;
@return rgba($red, $green, $blue, $opacity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.