迹忆客 专注技术分享

当前位置:主页 > 学无止境 > WEB前端 > JavaScript >

JavaScript 中的 RGB 颜色模型

作者:迹忆客 最近更新:2024/03/19 浏览次数:

CSS 的 color 属性表示元素的颜色,可以使用各种方式定义,例如 RGBHSLLCHHWBColor keyword 等。你可以阅读更多关于这些内容的信息表示颜色的各种方式在这里意味着:https://en.wikipedia.org/wiki/Color_theory。

RGB 是一种流行的颜色模型,所有浏览器都支持。RGB 代表红色、蓝色和绿色,也称为原色。这些原色的不同比例会产生更多的色调。

RGB 立方模型在 X 轴上表示红色,在 Y 轴上表示绿色,在 Z 轴上表示蓝色。如果三个坐标都在 0 处相遇,则代表黑色255 代表白色

RGB 颜色可以通过两种方式定义,功能方式和十六进制方式。

功能符号接受算术百分比每通道数字 8 位每通道数字 12 位每通道数字 16 位每通道数字 24 位颜色格式。可以通过两种方式定义十六进制表示法,使用 6 位数字3 位数字

JavaScript 中 rgb() 颜色的语法

rgb($red, $green, $blue);
rgba($red, $green, $blue, $alpha);
#RRGGBB[AA]
#RGB[A]

JavaScript 中 rgb() 颜色的参数

  • $red:这是一个强制性参数,用于定义最终颜色中红色脱落的强度。它的范围是 0-255 函数和 0-9, A-F 十六进制表示法。
  • $green:这是一个强制性参数,用于定义最终颜色中绿色脱落的强度。它的范围是 0-255 函数和 0-9, A-F 十六进制表示法。
  • $blue:这是一个强制性参数,用于定义最终颜色中蓝色脱落的强度。它的范围是 0-255 函数和 0-9, A-F 十六进制表示法。
  • $alpha:它是一个可选参数,用于定义颜色的透明度。它采用百分比值,浮点值。

示例代码:

<div id="demo">
  <h1>Hello world!</h1>
  <p>Welcome to RGB tutorial</p>
</div> 
div {
    color: rgb(12, 45, 255, 0.7);
    padding: 20px;
}
<script>
const tag = document.getElementById("demo");
tag.style.color = "rgb(255, 45, 255, 0.7)";
</script>

输出:

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

Do you understand JavaScript closures?

发布时间:2025/02/21 浏览次数:108 分类:JavaScript

The function of a closure can be inferred from its name, suggesting that it is related to the concept of scope. A closure itself is a core concept in JavaScript, and being a core concept, it is naturally also a difficult one.

Do you know about the hidden traps in variables in JavaScript?

发布时间:2025/02/21 浏览次数:178 分类:JavaScript

Whether you're just starting to learn JavaScript or have been using it for a long time, I believe you'll encounter some traps related to JavaScript variable scope. The goal is to identify these traps before you fall into them, in order to av

How much do you know about the Prototype Chain?

发布时间:2025/02/21 浏览次数:150 分类:JavaScript

The prototype chain can be considered one of the core features of JavaScript, and certainly one of its more challenging aspects. If you've learned other object-oriented programming languages, you may find it somewhat confusing when you start

用 jQuery 检查复选框是否被选中

发布时间:2024/03/24 浏览次数:102 分类:JavaScript

在本教程中学习 jQuery 检查复选框是否被选中的所有很酷的方法。我们展示了使用直接 DOM 操作、提取 JavaScript 属性的 jQuery 方法以及使用 jQuery 选择器的不同方法。你还将找到许多有用的

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便