Created
April 29, 2016 14:49
-
-
Save nosajio/0b42bd8c225eac978c91d8e56c00bc86 to your computer and use it in GitHub Desktop.
Modular scale stepper function, for moving up and down a modular scale.
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
/**! | |
* SCSS Modular scale function | |
* Will use $ms-base as the scale, and $degrees to calculate stops on the scale | |
* | |
* @author Jason Howmans <@jhwmns> | |
* | |
* @examples | |
* Usage example for font size: | |
* // Using a scale of 1.4, this will output font-size: 1.96rem; | |
* font-size: #{ms(2)}rem; | |
* | |
* Will also work with backward steps | |
* // Using a scale of 1.4, this will output font-size: .714rem; | |
* font-size: #{ms(-1)}rem; | |
*/ | |
$ms-base: 1.4; | |
@function ms($degrees:1) { | |
$num: 1; | |
$isNegative: false; | |
@if $degrees < 0 { | |
$isNegative: true; | |
$degrees: $degrees * -1; | |
} | |
@for $i from 1 through $degrees { | |
@if $isNegative { | |
$num: $num / $ms-base; | |
} @else { | |
$num: $num * $ms-base; | |
} | |
} | |
@return round($num * 1000) / 1000; // round to three decimal places | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment