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

html获取16个随机颜色并不重复

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>16个不重复随机颜色</title><style>* {margin: 0;padding: 0;box-sizing: border-box;font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;}body {background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);color: #fff;min-height: 100vh;padding: 20px;display: flex;flex-direction: column;align-items: center;}.container {max-width: 1200px;width: 100%;text-align: center;}h1 {margin: 20px 0;font-size: 2.8rem;text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);}.description {margin-bottom: 30px;font-size: 1.2rem;max-width: 800px;line-height: 1.6;}.colors-container {display: grid;grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));gap: 20px;width: 100%;margin-bottom: 40px;}.color-box {height: 150px;border-radius: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);transition: transform 0.3s ease, box-shadow 0.3s ease;overflow: hidden;cursor: pointer;}.color-box:hover {transform: translateY(-5px);box-shadow: 0 12px 20px rgba(0, 0, 0, 0.4);}.color-value {background-color: rgba(0, 0, 0, 0.5);padding: 8px 15px;border-radius: 20px;font-weight: bold;margin-top: 10px;backdrop-filter: blur(5px);}.controls {margin: 20px 0;display: flex;flex-wrap: wrap;gap: 15px;justify-content: center;align-items: center;}button {padding: 12px 25px;background: #2c3e50;color: white;border: none;border-radius: 30px;cursor: pointer;font-size: 1rem;font-weight: bold;transition: all 0.3s ease;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);}button:hover {background: #3498db;transform: translateY(-3px);box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);}.excluded-colors {margin-top: 30px;background: rgba(0, 0, 0, 0.2);padding: 20px;border-radius: 15px;max-width: 800px;}.excluded-colors h2 {margin-bottom: 15px;}.excluded-list {display: flex;flex-wrap: wrap;gap: 10px;justify-content: center;}.excluded-color {width: 50px;height: 50px;border-radius: 8px;display: flex;justify-content: center;align-items: center;font-size: 0.8rem;font-weight: bold;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);}.notification {position: fixed;top: 20px;left: 50%;transform: translateX(-50%);background: rgba(0, 0, 0, 0.8);color: white;padding: 15px 25px;border-radius: 30px;z-index: 1000;opacity: 0;transition: opacity 0.3s ease;}.show {opacity: 1;}@media (max-width: 768px) {.colors-container {grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));}h1 {font-size: 2rem;}}</style>
</head>
<body><div class="container"><h1>16个不重复随机颜色生成器</h1><p class="description">点击下方按钮生成16个独特的随机颜色,已排除您提供的颜色。点击颜色框可以复制色值到剪贴板。</p><div class="controls"><button id="generate-btn">生成新颜色</button><button id="copy-all-btn">复制所有色值</button></div><div class="colors-container" id="colors-container"><!-- 颜色框将通过JavaScript动态生成 --></div><div class="excluded-colors"><h2>已排除的颜色</h2><div class="excluded-list"><div class="excluded-color" style="background-color: #FFEA3B;">#FFEA3B</div><div class="excluded-color" style="background-color: #1569FF;">#1569FF</div><div class="excluded-color" style="background-color: #6462CC;">#6462CC</div><div class="excluded-color" style="background-color: #23B3FF;">#23B3FF</div><div class="excluded-color" style="background-color: #14FFF1;">#14FFF1</div><div class="excluded-color" style="background-color: #01B064;">#01B064</div></div></div></div><div class="notification" id="notification">颜色已复制到剪贴板</div><script>document.addEventListener('DOMContentLoaded', function() {const colorsContainer = document.getElementById('colors-container');const generateBtn = document.getElementById('generate-btn');const copyAllBtn = document.getElementById('copy-all-btn');const notification = document.getElementById('notification');// 需要排除的颜色列表const excludedColors = ['#FFEA3B', '#1569FF', '#6462CC', '#23B3FF', '#14FFF1', '#01B064'];// 生成随机颜色function generateRandomColor() {const letters = '0123456789ABCDEF';let color = '#';for (let i = 0; i < 6; i++) {color += letters[Math.floor(Math.random() * 16)];}return color;}// 生成16个不重复且不在排除列表中的颜色function generateUniqueColors() {const colors = new Set();while (colors.size < 16) {const color = generateRandomColor();if (!excludedColors.includes(color.toUpperCase()) && !colors.has(color)) {colors.add(color);}}return Array.from(colors);}// 显示颜色function displayColors() {colorsContainer.innerHTML = '';const colors = generateUniqueColors();colors.forEach(color => {const colorBox = document.createElement('div');colorBox.className = 'color-box';colorBox.style.backgroundColor = color;const colorValue = document.createElement('div');colorValue.className = 'color-value';colorValue.textContent = color;colorBox.appendChild(colorValue);colorsContainer.appendChild(colorBox);// 添加点击复制功能colorBox.addEventListener('click', () => {copyToClipboard(color);showNotification(`已复制: ${color}`);});});}// 复制到剪贴板function copyToClipboard(text) {const textarea = document.createElement('textarea');textarea.value = text;document.body.appendChild(textarea);textarea.select();document.execCommand('copy');document.body.removeChild(textarea);}// 显示通知function showNotification(message) {notification.textContent = message;notification.classList.add('show');setTimeout(() => {notification.classList.remove('show');}, 2000);}// 复制所有颜色function copyAllColors() {const colorBoxes = document.querySelectorAll('.color-value');const allColors = Array.from(colorBoxes).map(box => box.textContent).join('\n');copyToClipboard(allColors);showNotification('所有颜色值已复制到剪贴板');}// 初始化displayColors();// 事件监听generateBtn.addEventListener('click', displayColors);copyAllBtn.addEventListener('click', copyAllColors);});</script>
</body>
</html>

文章转载自:

http://yTJj2e9x.zpjhh.cn
http://KeDmUtlP.zpjhh.cn
http://lOh1hU2m.zpjhh.cn
http://cK5vymVF.zpjhh.cn
http://pIt85Zb0.zpjhh.cn
http://JhpQlSz8.zpjhh.cn
http://odeleWMC.zpjhh.cn
http://YxNRLGNW.zpjhh.cn
http://mFo763ww.zpjhh.cn
http://y2PcSgJi.zpjhh.cn
http://eEwHXrTe.zpjhh.cn
http://9OoYiHwF.zpjhh.cn
http://0lCEooeG.zpjhh.cn
http://3ZtCEXWW.zpjhh.cn
http://4Ut7oIOU.zpjhh.cn
http://GH5MUdhc.zpjhh.cn
http://2g8P0B4u.zpjhh.cn
http://LyK2iqla.zpjhh.cn
http://bw3I5QfE.zpjhh.cn
http://8awpCNfM.zpjhh.cn
http://huFuqib5.zpjhh.cn
http://WEA4dMfN.zpjhh.cn
http://wGYa5J8a.zpjhh.cn
http://SoMP5eaV.zpjhh.cn
http://UYljQy1M.zpjhh.cn
http://K7EJtgWR.zpjhh.cn
http://uAlKh79e.zpjhh.cn
http://MUxX87my.zpjhh.cn
http://dB1z8elN.zpjhh.cn
http://ig0VLs6x.zpjhh.cn
http://www.dtcms.com/a/378732.html

相关文章:

  • 数据库开启ssl
  • 12V转18V/2A车灯方案:宽输入电压、支持PWM调光的车灯驱动芯片FP7208
  • get post 请求
  • 如何在Anaconda中配置你的CUDA Pytorch cuNN环境(2025最新教程)
  • 关于大模型提示词设计的思路探讨
  • 软考-系统架构设计师 信息加解密技术详细讲解
  • 人工鱼群算法AFSA优化支持向量机SVM,提高故障分类精度
  • 《RAD Studio 13.0》 [DELPHI 13.0] [官方原版IOS] 下载
  • 最小曲面问题的欧拉-拉格朗日方程 / 曲面极值问题的变分法推导
  • kotlin的函数前面增加suspend关键字的作用
  • Linux vi/vim
  • 赋能高效设计:12套中后台管理信息系统通用原型框架
  • Spark 核心 RDD详解
  • 图灵奖得主萨顿演讲解读:深度学习的局限与AI新范式
  • 香港券商柜台系统搭建与开发技术分析
  • React学习教程,从入门到精通,React 组件生命周期详解(适用于 React 16.3+,推荐函数组件 + Hooks)(17)
  • EFK+DeepSeek 智能运维方案:技术架构与实施步骤
  • 零基础快速了解掌握Linux防火墙-Iptables
  • python---PyInstaller(将Python脚本打包为可执行文件)
  • Python 数据类型转换完全指南:方法与最佳实践
  • 冷压对辊矫平机:金属板材的“应力按摩师”
  • Django REST Framework响应类Response详解
  • 一款.NET开发的AI无损放大工具
  • linux安装远程桌面图形化界面以及root登录
  • 短视频流量算法
  • 前端网络性能优化实践:从 HTTP 请求到 HTTPS 与 HTTP/2 升级
  • 37.循环神经网络:让AI理解序列
  • 合集:Git代码托管平台
  • Python 高效实现 Word 转 PDF:告别 Office 依赖
  • flutter配置Android gradle kts 8.0 的打包名称