当前位置: 首页 > news >正文

iro.js 非常方便好用的 Web 颜色选择器

在这里插入图片描述

iro.js 非常方便好用的 Web 颜色选择器

github:https://github.com/jaames/iro.js
例子:https://codepen.io/jaames/pen/XWbgwYm

一、vue 中使用

1. 安装组件

yarn add @jaames/iro

2. 在组件中使用

<script setup lang="ts">
import iro from "@jaames/iro";onMounted(() => {const colorPicker = new iro.ColorPicker('.color-picker', {width: 100,color: bgColor.value,layoutDirection: "horizontal",layout: [{component: iro.ui.Wheel,},{component: iro.ui.Box,},{component: iro.ui.Slider,options: {sliderType: 'hue'}},{component: iro.ui.Slider,options: {sliderType: 'saturation'}},{component: iro.ui.Slider,options: {sliderType: 'value'}},{component: iro.ui.Slider,options: {sliderType: 'alpha'}},]})colorPicker.on('color:change', color => {bgColor.value = color.hexStringconsole.log(bgColor.value)})
})
</script>
<template><div ref="refColorPicker" class="color-picker"></div>
</template>

3. 结果

在这里插入图片描述
在这里插入图片描述

二、普通 html 文件中使用

1. 下载 iro.js 原文件

下载后,放到你的项目目录中,自己能找到就行
https://github.com/jaames/iro.js/raw/refs/heads/master/dist/iro.min.js

2. 引用它

  <script src="./iro.min.js"></script>

在这里插入图片描述

3. 使用它

在 html 中预置一个 .color-picker 的 div,这个名字随便起,只要在使用的时候对应上就可以。
iro 组件会在这个元素中生成。

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title>Drop and Show</title><link rel="shortcut icon" href="favicon.png" type="image/png"><link rel="stylesheet" href="drop.css?v=20250321171641"><script src="./iro.min.js"></script>
</head>
<body >
<div class="header"><div class="color-picker"></div>
</div>
</body>
</html><script>
/**=======================================*    COLOR PICKER=======================================*/let bgColor = localStorage.getItem('bg-color') || "rgba(0,0,0,0.98)"$('.container').style.backgroundColor = bgColorconst colorPicker = new iro.ColorPicker('.color-picker', {width: 50,color: bgColor,layoutDirection: "horizontal",})colorPicker.on('color:change', color => {localStorage.setItem('bg-color', color.hexString)// 在颜色变化的时候,将这个颜色应用到了 .container 中$('.container').style.backgroundColor = color.hexString$('.modal').style.backgroundColor = color.hexString})
</script>

三、实际应用的例子

这里有应用实例:

  • github:https://github.com/KyleBing/drop-and-show
  • 在线实例:http://kylebing.cn/tools/drop-and-show/

在这里插入图片描述

相关文章:

  • 【Redis篇】linux 7.6安装单机Redis7.0(参数优化详解)
  • 【容器化】Docker容器技术入门基础教程
  • 端口隔离基本配置
  • 如何保障服务器租用中的数据安全?
  • ‌2.4GHz无线通信天线布局与优化方法
  • 基于C++的IOT网关和平台7:github项目ctGateway设备协议开发指南
  • AutoDL+SSH在vscode中远程使用GPU训练深度学习模型
  • 论文AI率降低 教程(包过)
  • 分布式、高并发-Day03
  • 人工智能与智能合约:如何用AI优化区块链技术中的合约执行?
  • Paramiko 性能优化详解
  • 生成了一个AI算法
  • 华为设备端口隔离
  • 【Azure Redis】Redis导入备份文件(RDB)失败的原因
  • NVIDIA Halos:智能汽车革命中的全栈式安全系统
  • Selenium模拟人类,操作网页的行为(全)
  • 强啊!Oracle Database 23aiOracle Database 23ai:使用列别名进行分组排序!
  • Oracle04-基本使用
  • 26届秋招收割offer指南
  • JavaScript性能优化实战:深入探讨性能瓶颈与优化技巧
  • 库里22分赢下抢七大战,火箭10年难破“火勇大战”的魔咒
  • 体坛联播|拜仁提前2轮德甲夺冠,赵心童11比6暂时领先
  • 农村青年寻路纪|劳动者的书信⑤
  • 魔都眼|上海环球马术冠军赛收官,英国骑手夺冠
  • 张求会谈陈寅恪的生前身后事
  • 美国鞋类巨头请求白宫豁免关税,称已构成“生存威胁”