Skip to content

Instantly share code, notes, and snippets.

@dovidweisz
Last active March 22, 2024 10:45
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dovidweisz/e659d4e7cead1676c86c4f396e4d7b18 to your computer and use it in GitHub Desktop.
Save dovidweisz/e659d4e7cead1676c86c4f396e4d7b18 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
@function opacitator($color){
$hi: 1;
$lo: 0;
$tol: 0.01;
$rgbs: (red($color) green($color) blue($color));
@while($hi - $lo > $tol){
$m: $lo + (($hi - $lo) / 2);
@if(getOpositesForOpacity($m, $rgbs, true)){
$hi: $m;
}
@else{
$lo: $m;
}
}
$rgbs: getOpositesForOpacity($hi, $rgbs);
@return rgba( nth($rgbs, 1), nth($rgbs, 2), nth($rgbs, 3), $hi);
}
@function getOpositesForOpacity($opacity, $rgbs, $returnValidity: false){
$newList: ();
$valid: true;
@each $c in $rgbs{
$newVal: oppositeForOpacity($opacity, $c);
@if( $newVal >= 0 ){
$newList: append($newList, $newVal);
}
@else{
@return false;
}
}
@if($returnValidity ){
@return $valid;
}
@else{
@return $newList;
}
}
@function oppositeForOpacity($opacity, $c){
@return 255 - ( 255 - $c ) / $opacity;
}
$myColor: #f35684;
i{
background-color: opacitator(#f35684);
}
i {
background-color: rgba(237, 1, 70, 0.66406);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment