目录

average

描述 (Description)

average函数基于每个通道(RGB)计算两种输入颜色的平均值。

参数 (Parameters)

  • color1 - 一个颜色对象。

  • color2 - 一个颜色对象。

返回值 (Returns)

颜色

例子 (Example)

以下示例演示了在LESS文件中使用average函数 -

<html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
   </head>
   <body>
      <h2>Average Function</h2>
      <div class = "color1">
         <p>(color1) <br> #ff6600</p>
      </div><br>
      <div class = "color2">
         <p>(color2) <br> #0000ff</p>
      </div><br>
      <div class = "res">
         <p>(result) <br> #803380</p>
      </div>
   </body>
</html>

接下来,创建style.less文件。

style.less

.color1 {
   width: 100px;
   height: 100px;
   background-color: #ff6600;
}
.color2 {
   width: 100px;
   height: 100px;
   background-color: #0000ff;
}
.res {
   width: 100px;
   height: 100px;
   background-color: average(#ff6600, #0000ff);
}
p {
   padding: 30px 0px 0px 25px;
}

您可以使用以下命令将style.less编译为style.css -

lessc style.less style.css

执行上面的命令; 它将使用以下代码自动创建style.css文件 -

style.css

.color1 {
   width: 100px;
   height: 100px;
   background-color: #ff6600;
}
.color2 {
   width: 100px;
   height: 100px;
   background-color: #0000ff;
}
.result {
   width: 100px;
   height: 100px;
   background-color: #803380;
}
p {
   padding: 30px 0px 0px 25px;
}

输出 (Output)

请按照以下步骤查看上述代码的工作原理 -

  • 将以上代码保存在color_blending_average.html文件中。

  • 在浏览器中打开此HTML文件,将显示以下输出。

较少的颜色混合功能
↑回到顶部↑
WIKI教程 @2018