2019-04-30 11:11:25 +08:00
|
|
|
//下一个断点
|
2019-05-15 16:10:20 +08:00
|
|
|
@function breakpoint-next(
|
2019-12-06 09:58:08 +08:00
|
|
|
$name,
|
|
|
|
$breakpoints: breakpoints,
|
|
|
|
$breakpoint-names: map-keys($breakpoints)
|
2019-05-15 16:10:20 +08:00
|
|
|
) {
|
2019-12-06 09:58:08 +08:00
|
|
|
$n: index($breakpoint-names, $name);
|
|
|
|
@return if(
|
|
|
|
$n < length($breakpoint-names),
|
|
|
|
nth($breakpoint-names, $n + 1),
|
|
|
|
null
|
|
|
|
);
|
2019-04-30 11:11:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//断点最小值
|
|
|
|
@function breakpoint-min($name, $breakpoints: $breakpoints) {
|
2019-12-06 09:58:08 +08:00
|
|
|
$min: map-get($breakpoints, $name); // @return if($min != 0, $min, null);
|
|
|
|
@return $min;
|
2019-04-30 11:11:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//断点最大值
|
|
|
|
@function breakpoint-max($name, $breakpoints: $breakpoints) {
|
2019-12-06 09:58:08 +08:00
|
|
|
$next: breakpoint-next($name, $breakpoints);
|
|
|
|
@return if($next, breakpoint-min($next, $breakpoints) - 1px, null);
|
2019-04-30 11:11:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//生成类名“-sm、-md、-lg、-cl” -xs?
|
|
|
|
@function breakpoint-infix($name, $breakpoints: $breakpoints) {
|
2019-12-06 09:58:08 +08:00
|
|
|
@return if(breakpoint-min($name, $breakpoints) ==null, '', '-#{$name}');
|
2019-04-30 11:11:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@function px2rem($pixels, $context: $remFactor) {
|
2019-12-06 09:58:08 +08:00
|
|
|
@if (unitless($pixels)) {
|
|
|
|
$pixels: $pixels * 1px;
|
|
|
|
}
|
2019-05-15 16:10:20 +08:00
|
|
|
|
2019-12-06 09:58:08 +08:00
|
|
|
@if (unitless($context)) {
|
|
|
|
$context: $context * 1px;
|
|
|
|
}
|
2019-05-15 16:10:20 +08:00
|
|
|
|
2019-12-06 09:58:08 +08:00
|
|
|
@return $pixels / $context * 1rem;
|
2019-05-15 16:10:20 +08:00
|
|
|
}
|