Last active
March 22, 2024 10:45
-
-
Save dovidweisz/e659d4e7cead1676c86c4f396e4d7b18 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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
// ---- | |
// 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); | |
} |
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
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