徐徐爱coding
  • 首页
  • 爱情买卖
  • 导航
  • 私语
  • 友情链接
  • 关于
    关于本站
    知识库
    弹钢琴
徐徐爱coding

徐徐爱coding

徐徐爱coding是一个个人博客站点,记录编程经历的点点滴滴,分享自己的所见与所得,坚持自己的初心,践行自己的梦想生活不是等着暴风雨过去,而是学会在风雨中跳舞!

Copyright © 2023 徐徐爱coding All Rights Reserved.
陕公网安备61019602000456陕ICP备2023007787号-2

网站已稳定运行

js生成随机颜色

js生成随机颜色

徐徐
前端
#javascript
23 热度0 评论25 点赞
发布于2024-08-04 15:06:02
🌺前言
js生成暗色,亮色的几种方法

typescript
/**
 * 生成亮色
 * @returns
 */
export function randomBrightColor() {
  const saturation = Math.random(); // 饱和度在0到1之间
  const brightness = Math.random(); // 亮度在0到1之间
  return `hsl(${Math.random() * 360}, ${saturation * 100}%, ${brightness * 100}%)`;
}
/**
 *生成暗色
 * @returns
 */
export function randomDarkColor() {
  const saturation = Math.random(); // 饱和度在0到1之间
  const lightness = 1 - Math.random(); // 亮度在0到1之间,并保证是暗色
  return `hsl(${Math.random() * 360}, ${saturation * 100}%, ${lightness * 100}%)`;
}
/**
 * 现颜色
 * @returns 
 */
export function randomPrettyColor() {
    const randomHue = Math.random(); // 生成一个0到1之间的随机数作为色相
    const saturation = 0.4 + Math.random() * 0.6; // 饱和度:0.4到1之间
    const lightness = 0.4 + Math.random() * 0.4; // 亮度:0.4到0.8之间
    const hsl = `hsl(${randomHue * 360}, ${saturation * 100}%, ${lightness * 100}%)`;
   
    return hsl;
  }
文章最后更新于 2024-08-11 23:08:44
作者:徐徐
版权声明:转载请注明文章出处
留言
暂无数据

~~空空如也