Created
April 30, 2015 14:37
-
-
Save KittyGiraudel/d3f58500d75088b05c2f to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or 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.13) | |
// Compass (v1.0.3) | |
// ---- | |
/// Get closest element of $list from $number | |
/// @author Hugo Giraudel | |
/// @param {List} $list - List of numbers | |
/// @param {Number} $number - Number to get closest item from | |
/// @return {Number} | |
/// @example | |
/// closest(34 46 469 34 1, 42); | |
/// // -> 46 | |
@function closest($list, $number) { | |
$current: nth($list, 1); | |
@each $value in $list { | |
@if abs($number - $value) < abs($number - $current) { | |
$current: $value | |
} | |
} | |
@return $current; | |
} | |
// Test | |
.foo { | |
$list: (34, 46, 90, 77, 1); | |
@for $i from 1 through 100 { | |
content: closest($list, $i); | |
} | |
} |
This file contains hidden or 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
.foo { | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 1; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 34; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 46; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 77; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
content: 90; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment