Skip to content

Instantly share code, notes, and snippets.

@jakob-e
Last active December 23, 2015 04:39
Show Gist options
  • Save jakob-e/6581310 to your computer and use it in GitHub Desktop.
Save jakob-e/6581310 to your computer and use it in GitHub Desktop.
// Strip units (from unit conversion)
@function number($val){
@if($val==null){ @return null;}
@return $val/($val*0+1);
}
// ======================
// Inbuild
// ======================
// floor
// ceil
// abs
// min
// max
// Returns the closest number within the range of min and max
// E.g. clamp(-20, 10, 30) will return 10
@function clamp($val, $min, $max) {
$val:number($val); $min:number($min); $max:number($max);
@return if($val > $max, $max,
if($val < $min, $min,
$val));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment