Created
January 25, 2013 06:06
-
-
Save matori/4632140 to your computer and use it in GitHub Desktop.
scss color shade funtion
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
// color shade function | |
// @link http://www.colorhexa.com/ | |
$shade-step: 100% / 13; | |
@function x-color-shade($target-color, $steps: 0) { | |
$lightness: $shade-step * $steps; | |
$return-color: null; | |
@if $lightness > 0 { | |
$return-color: lighten($target-color, $lightness); | |
} @else if $lightness < 0 { | |
$return-color: darken($target-color, $lightness * -1); | |
} @else { | |
$return-color: $target-color; | |
} | |
@return $return-color; | |
} | |
// Test | |
/* | |
* base color: #09c | |
*/ | |
/* | |
* Result | |
* @link http://sassmeister.com/gist/4632140 | |
* @link http://www.colorhexa.com/0099cc | |
*/ | |
$base-color: #09c; | |
/* x-color-shade() の第二引数に 1 ~ 9 を指定 */ | |
@for $i from 1 through 9 { | |
.lighten-#{$i} { color: x-color-shade($base-color, $i); } | |
} | |
/* x-color-shade() の第二引数に 0 を指定 */ | |
.shade-0 { color: x-color-shade($base-color, 0); } | |
/* x-color-shade() の第二引数に何も指定しない */ | |
.shade-null { color: x-color-shade($base-color); } | |
/* x-color-shade() の第二引数に -1 ~ -9 を指定 */ | |
@for $i from 1 through 9 { | |
.darken-#{$i} { color: x-color-shade($base-color, $i * -1); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment