javascript在线随机生成可预览的随机背景颜色

所属分类: 网页特效-实用工具    2024-01-04 10:36:34

javascript在线随机生成可预览的随机背景颜色 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript在线随机生成可预览的随机背景颜色(共3个文件)

    • index.html

使用方法

// Some Variables 
var genButton = document.getElementById("gen"), // Generate button
    clear  = document.getElementById("clear"),  // Clear button
    output = document.getElementById("randomNum"),  // Output space
    copy = document.getElementById("copy"),  // Copy to Clipboard Button
    copyCheck = document.getElementById("copyCheck");  // copy check
  

// Get Random Number Function && make it the background of the body xD
function getRandomNum() {
    "use strict";
    output.value = "#" + Math.floor((1e+5) + Math.random() * (9e+5)); // get random 6-digits number
  var bgClr = output.value; 
  document.getElementById("preview").style.backgroundColor = bgClr;  // set body bgColor to that random number
}
// Clear Random Number Function + make background of the body as default 
function clearNum() {
    "use strict";
    output.value = "";   // clear output space
   document.getElementById("preview").style.backgroundColor = "#F1A9A0";   // make bgColor of the body as default
}
// Copy the color code to the clipboard by clicking on "Copy" Button
function copyToClipBoard() {
  "use strict";
  document.execCommand("copy", false, output.select());
  copyCheck.style.right = "20px";
  showCheck = setTimeout(function() {
    copyCheck.style.right = "-200px";
  }, 3000);
  clearTimeout(showCheck);
}
// Adding EventListener to the buttons
genButton.addEventListener("click", getRandomNum);  // Generate Button
clear.addEventListener("click", clearNum);   // Clear Button
copy.addEventListener("click", copyToClipBoard);

//---------------- Thanks for being here --------------------- //

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

jquery通过AJAX请求延迟执行函数插件

一款轻量级延迟执行函数插件,可通过AJAX动态请求自定义时间后要执行的函数。
  实用工具
 1623  0

jquery可自定义设置的密码生成器插件

一款可在线设置的密码生成器,可生成带有数字/字母/符号(特殊字符)的随机强密码,带滑块设置密码长度。
  实用工具
 7834  0

jquery检测客户端浏览器及系统版本插件

一款浏览器和平台检测插件,用户代理检测客户端浏览器(类型和版本)、操作系统、设备类型和其他util信息。
  实用工具
 1682  0

jquery基于Fetch API天气信息插件

一款基于第三方接口的在线天气查询,可输入英文城市名查询天气信息,需要开启浏览器位置信息。
  实用工具
 8554  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论