Last active
July 25, 2017 18:18
-
-
Save rzkhosroshahi/2db1772e19ef9956eef78a31a0a4590b to your computer and use it in GitHub Desktop.
This snippet computing golden ratio field for SASS/SCSS
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
@function scaleMath($n) { | |
@if $n == 0 {@return 1;} | |
@if $n == 1 {@return 1.618;} | |
@if $n == -1 {@return 0.618;} | |
@if $n > 0{ | |
@return scaleMath($n - 1) + scaleMath($n - 2); | |
} | |
@if $n < 0 { | |
@return scaleMath($n + 2) - scaleMath($n + 1); | |
} | |
} | |
// example | |
.container { | |
width: #{scaleMath(-3)}; // 0.236 | |
} | |
// or | |
@function scaleRem($val){ | |
@return #{scaleMath($val)}rem; | |
} | |
.container { | |
width: scaleRem(2); // 2.618rem | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment