检查此功能
@function mathOperation($number, $type) {
@if $type == sum or $type == rest {
@return true
} @else {
@return false
}
}
@debug mathOperation(5, sum);
@debug mathOperation(5, rest);
@debug mathOperation(5, division);
正如预期的那样结果就是这个
DEBUG:true
DEBUG:true
DEBUG:false
但是如果我们将此函数中的相等运算符修改为!=
@function mathOperation2($number, $type) {
@if $type != sum or $type != rest {
@return true
} @else {
@return false
}
}
@debug mathOperation2(5, sum);
@debug mathOperation2(5, rest);
@debug mathOperation2(5, division);
结果变得奇怪
DEBUG:true
DEBUG:true
DEBUG:true
我错过了什么吗?这种行为是一个错误吗?我正在使用grunt-sass 2.1.0进行编译答案 0 :(得分:0)
对于第二个示例,代码应为:
@function mathOperation2($number, $type) {
@if $type != sum and $type != rest {
@return true
} @else {
@return false
}
}
or
语句中的if
表示如果其中一个条件为真,则接受该条件。你应该使用and
所以如果两个陈述都是真的那么条件将是tru。
答案 1 :(得分:0)
非常感谢您的回答,我在最近5天没有睡觉(儿子住院)我用地图解决了这个问题:
@function map-select-key($map, $key, $direction) {
$direction-map: (previous: -1, next: 1);
@if map-has-key($direction-map, $direction) == false {
@warn '#{$direction} is not an accepted parameter, the only
parameters accepted for $direction are "#{map-keys($direction-map)}"';
@return null;
} @else if (map-index-from-key($map, $key) == 1) and ($direction == previous) or (map-index-from-key($map, $key) == length($map)) and ($direction == next) {
@warn 'it is not possible to select the #{$direction} item: #{$key} is the #{if($direction == previous, first, last)} element on the map #{$map}';
@return null;
} @else {
@return map-key-from-index($map, map-index-from-key($map, $key) + map-get($direction-map, $direction));
}
}