Skip to content

Instantly share code, notes, and snippets.

@nosajio
Created April 29, 2016 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nosajio/0b42bd8c225eac978c91d8e56c00bc86 to your computer and use it in GitHub Desktop.
Save nosajio/0b42bd8c225eac978c91d8e56c00bc86 to your computer and use it in GitHub Desktop.
Modular scale stepper function, for moving up and down a modular scale.
/**!
* 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