• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • sass:math

    变量

    math.$e

    等于数学常数e的值。

    @debug math.$e; // 2.7182818285
    


    math.$pi

    等于数学常数π的值。

    @debug math.$pi; // 3.1415926536
    


    边界函数

    math.ceil()

    math.ceil($number)
    ceil($number) //=> number
    

    四舍五入$number到下一个最大的整数。

    @debug math.ceil(4); // 4
    @debug math.ceil(4.2); // 5
    @debug math.ceil(4.9); // 5
    


    math.clamp()

    math.clamp($min, $number, $max) //=> number 
    

    $number限制在$min$max之间。如果$number小于$min,则返回$min;如果大于$max,则返回$max$min$number$max必须具有兼容的单元,或者都是无单元的。

    @debug math.clamp(-1, 0, 1); // 0
    @debug math.clamp(1px, -1px, 10px); // 1px
    @debug math.clamp(-1in, 1cm, 10mm); // 10mm
    


    math.floor()

    math.floor($number)
    floor($number) //=> number
    

    向下舍入$number到下一个最小的整数。

    @debug math.floor(4); // 4
    @debug math.floor(4.2); // 4
    @debug math.floor(4.9); // 4
    


    math.max()

    math.max($number...)
    max($number...) //=> number
    

    返回一个或多个数字中的最大值。

    @debug math.max(1px, 4px); // 4px
    
    $widths: 50px, 30px, 100px;
    @debug math.max($widths...); // 100px
    


    math.min()

    math.min($number...)
    min($number...) //=> number
    

    返回一个或多个数字中的最小值。

    @debug math.min(1px, 4px); // 1px
    
    $widths: 50px, 30px, 100px;
    @debug math.min($widths...); // 30px
    


    math.round()

    math.round($number)
    round($number) //=> number
    

    四舍五入$number到最接近的整数。

    @debug math.round(4); // 4
    @debug math.round(4.2); // 4
    @debug math.round(4.9); // 5
    


    距离函数

    math.abs()

    math.abs($number)
    abs($number) //=> number
    

    返回$number的绝对值。如果$number为负,则返回-$number,如果$number为正,则按原样返回$number

    @debug math.abs(10px); // 10px
    @debug math.abs(-10px); // 10px
    


    math.hypot()

    math.hypot($number...) //=> number
    

    返回具有等于每个$number的分量的n维向量的长度。例如,对于三个数字a、b和c,这将返回a²+b²+c²的平方根。这些数字必须要么都具有兼容的单位,要么都没有单位。由于数字的单位可能不同,因此输出采用第一个数字的单位。

    @debug math.hypot(3, 4); // 5
    
    $lengths: 1in, 10cm, 50px;
    @debug math.hypot($lengths...); // 4.0952775683in
    


    指数函数

    math.log()

    math.log($number, $base: null) //=> number 
    

    返回$number相对于$base的对数。如果$base为空,则计算自然对数。$number$base必须是无单位的。

    @debug math.log(10); // 2.302585093
    @debug math.log(10, 10); // 1
    

    math.pow()

    math.pow($base, $exponent) //=> number 
    

    $base提高到$exponent的幂。$base$exponent必须是无单位的。

    @debug math.pow(10, 2); // 100
    @debug math.pow(100, math.div(1, 3)); // 4.6415888336
    @debug math.pow(5, -2); // 0.04
    

    math.sqrt()

    math.sqrt($number) //=> number
    

    返回$number的平方根。$number必须是无单位的。

    @debug math.sqrt(100); // 10
    @debug math.sqrt(math.div(1, 3)); // 0.5773502692
    @debug math.sqrt(-1); // NaN
    


    三角函数

    math.cos()

    math.cos($number) //=> number 
    

    返回$number的余弦。$number必须是角度(其单位必须与deg兼容)或无单位。如果$number没有单位,,则假设其单位为rad

    @debug math.cos(100deg); // -0.1736481777
    @debug math.cos(1rad); // 0.5403023059
    @debug math.cos(1); // 0.5403023059
    


    math.sin()

    math.sin($number) //=> number
    

    返回$number的正弦值。$number必须是角度(其单位必须与deg兼容)或无单位。如果$number没有单位,则假设其单位为rad

    @debug math.sin(100deg); // 0.984807753 
    @debug math.sin(1rad); // 0.8414709848 
    @debug math.sin(1); // 0.8414709848 
    


    math.tan()

    math.tan($number) //=> number 
    

    返回$number的正切。$number必须是角度(其单位必须与deg兼容)或无单位。如果$number没有单位,则假设其单位为rad

    @debug math.tan(100deg); // -5.6712818196
    @debug math.tan(1rad); // 1.5574077247
    @debug math.tan(1); // 1.5574077247
    


    math.acos()

    math.acos($number) //=> number
    

    返回以度为单位的$number的反余弦。$number必须是无单位的。

    @debug math.acos(0.5); // 60deg
    @debug math.acos(2); // NaNdeg
    


    math.asin()

    math.asin($number) //=> number
    

    返回以度为单位的$number的反正弦值。$number必须是无单位的。

    @debug math.asin(0.5); // 30deg
    @debug math.asin(2); // NaNdeg
    


    math.atan()

    math.atan($number) //=> number 
    

    返回以度为单位的$number的反正切值。$number必须是无单位的。

    @debug math.atan(10); // 84.2894068625deg
    


    math.atan2()

    math.atan2($y, $x) //=> number 
    

    返回以度为单位的$y$x的2参数反正切。$y$x必须具有兼容的单位或无单位。

    math.atan2($y,$x)是不同的,atan(math.div($y,$x))因为它保留了相关点的象限。例如,math.atan2(1,-1)对应点(-1, 1)并返回 135deg。相反,math.atan(math.div(1,-1))math.atan(math.div(-1, 1))首先解析为atan(-1),因此两者都返回-45deg
    @debug math.atan2(-1, 1); // 135deg
    


    单位功能

    math.compatible()

    math.compatible($number1, $number2)
    comparable($number1, $number2) //=> boolean
    

    返回是否$number1$number2具有兼容的单位。如果返回true$number1并且$number2可以安全地进行加法、减法和比较。否则,这样做会产生错误。

    ⚠️注意!
    该函数的全局名称是可比较的,但当它被添加到 sass:math 模块时,名称被更改为 compatible,以更清楚地传达函数的功能。
    @debug math.compatible(2px, 1px); // true
    @debug math.compatible(100px, 3em); // false
    @debug math.compatible(10cm, 3mm); // true
    


    math.is-unitless()

    math.is-unitless($number)
    unitless($number) //=> boolean
    

    返回是否$number没有单位。

    @debug math.is-unitless(100); // true
    @debug math.is-unitless(100px); // false
    


    math.unit()

    math.unit($number)
    unit($number) //=> quoted string
    

    返回$number单位的字符串表示形式。

    ⚠️注意!
    该功能用于调试;它的输出格式不能保证在 Sass 版本或实现中保持一致。
    @debug math.unit(100); // ""
    @debug math.unit(100px); // "px"
    @debug math.unit(5px * 10px); // "px*px"
    @debug math.unit(math.div(5px, 1s)); // "px/s"
    


    其他功能

    math.div()

    math.div($number1, $number2) //=> number
    

    返回将$number1除以$number2的结果。两个数字共享的任何单元都将被取消。$number1中不在$number2中的单位将在返回值的分子中结束,而$number2中不在$number1中的单位将在其分母中结束。

    ⚠️注意!
    出于向后兼容的目的,这将返回与不推荐使用的/运算符完全相同的结果,包括将两个字符串连接在一起并在它们之间使用/字符。然而,这种行为最终将被删除,不应在新的样式表中使用。
    @debug math.div(1, 2); // 0.5
    @debug math.div(100px, 5px); // 20
    @debug math.div(100px, 5); // 20px
    @debug math.div(100px, 5s); // 20px/s
    


    math.percentage()

    math.percentage($number)
    percentage($number) //=> number
    

    将无单位$number(通常是 0 和 1 之间的小数)转换为百分比。

    此功能与$number * 100%

    @debug math.percentage(0.2); // 20%
    @debug math.percentage(math.div(100px, 50px)); // 200%
    


    math.random()

    math.random($limit: null)
    random($limit: null) //=> number
    

    如果$limitnull,则返回 0 到 1 之间的随机十进制数。

    @debug math.random(); // 0.2821251858
    @debug math.random(); // 0.6221325814
    

    如果$limit是大于或等于 1 的数字,则返回 1 和$limit之间的随机整数。

    @debug math.random(10); // 4
    @debug math.random(10000); // 5373
    

    上篇:sass:map

    下篇:sass:meta