wangchao.org
添加收藏 | 博客
 
购物视频论坛IT业界自然风光美女图片王朝网络小游戏BT下载生活百科编程设计手机图片小说
 
笑话 | 水库 | 娱乐 | 体育 | 英语 | 宠物 | 美食 | 旅游 | 养生 | 手机 | 数码 | 汽车 | 珠宝 | 美容 | 装修 | 厨房 | 科普 | 动物 | 植物 | 影音 | 百科 | 知道 | 词典
  
 
 您好! 您现在位于: 王朝网络 → 编程设计 → 《Javascript简易调色板效果返回上一页 
 
1楼 

Javascript简易调色板效果

  网上购物、在线购物、购物搜索 欢迎光临本站购买图书、影视、音乐、数码、百货,手机等商品。

  调用方法:colorSelect('色值输入框ID','显示色值的容器ID',event),调用起来很简单,直接onClick就可以。 感谢:红辣椒
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>调色板</title>
  <style>
  #colorBoard{position:absolute; padding:10px; width:256px; height:220px; background:#f3f3f3; border:#d9d9d9 1px solid;}
  #colorBank{ clear:both; border:#d9d9d9 1px solid; background:#FFF; width:252px; padding:0 0 2px 2px; overflow:hidden; margin:0 auto 0 auto;}
  #colorBank div{ overflow:hidden; height:12px; width:12px; margin:2px 2px 0 0; float:left; overflow:hidden; cursor:pointer;}
  #colorViews{width:80px; height:20px; float:left;border:#d9d9d9 1px solid; background:#000; display:block; margin: 0 10px 10px 0;}
  #colorInput{width:70px; height:18px; float:left; font-family:Verdana; font-size:13px; color:#333; display:block; border:none; background:#FFF;border:#d9d9d9 1px solid;margin: 0 10px 10px 0;}
  #colorClose{width:80px; color:#999999; height:22px; float:left;display:block; background:#f3f3f3;cursor:pointer;border:#d9d9d9 1px solid; border-top:#FFF 1px solid; border-left:#FFF 1px solid;}
  </style>
  <script>
  function colorSelect(now,page,e){
  if(document.getElementById("colorBoard")){
   return;
  }
  //关于出现位置
  e=e||event;
  var scrollpos = getScrollPos();
  var l = scrollpos.l + e.clientX;
   var t = scrollpos.t + e.clientY + 10;
   if (l > getBody().clientWidth-253){
   l = getBody().clientWidth-253;
   }
  //创建DOM
  var nowColor = document.getElementById(now);
  var pageColorViews = document.getElementById(page);
  var ColorHex=new Array('00','33','66','99','CC','FF');
  var SpColorHex=new Array('FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF');
  var colorBank = document.createElement("div");
  colorBank.setAttribute("id","colorBank");
  var colorViews = document.createElement("div");
  colorViews.setAttribute("id","colorViews");
  var colorInput = document.createElement("input");
  colorInput.setAttribute("id","colorInput");
  colorInput.setAttribute("type","text");
  colorInput.setAttribute("disabled","disabled");
  var colorClose = document.createElement("input");
  colorClose.setAttribute("id","colorClose");
  colorClose.setAttribute("value","取消");
  colorClose.setAttribute("type","button");
  colorClose.onclick=function(){document.body.removeChild(colorBoard)};
  var colorBoard =document.createElement("div");
  colorBoard.id="colorBoard";
  colorBoard.style.left = l+"px";
  colorBoard.style.top = t+ "px";
  colorBoard.appendChild(colorViews);
  colorBoard.appendChild(colorInput);
  colorBoard.appendChild(colorClose);
  colorBoard.appendChild(colorBank);
  document.body.appendChild(colorBoard);
  //循环出调色板
  for(b=0;b<6;b++){
   for(a=0;a<3;a++){
   for(i=0;i<6;i++){
   colorItem = document.createElement("div");
   colorItem.style.backgroundColor="#"+ColorHex[a]+ColorHex[i]+ColorHex[b];
   colorBank.appendChild(colorItem);
   }
   }
  }
  for(b=0;b<6;b++){
   for(a=3;a<6;a++){
   for(i=0;i<6;i++){
   colorItem = document.createElement("div");
   colorItem.style.backgroundColor="#"+ColorHex[a]+ColorHex[i]+ColorHex[b];
   colorBank.appendChild(colorItem);
   }
   }
  }
  for(i=0;i<6;i++){
   colorItem = document.createElement("div");
   colorItem.style.backgroundColor="#"+ColorHex[0]+ColorHex[0]+ColorHex[0];
   colorBank.appendChild(colorItem);
  }
  for(i=0;i<6;i++){
   colorItem = document.createElement("div");
   colorItem.style.backgroundColor="#"+ColorHex[i]+ColorHex[i]+ColorHex[i];
   colorBank.appendChild(colorItem);
  }
  for(i=0;i<6;i++){
   colorItem = document.createElement("div");
   colorItem.style.backgroundColor="#"+SpColorHex[i];
   colorBank.appendChild(colorItem);
  }
  var colorItems = colorBank.getElementsByTagName("div");
  for(i=0; i<colorItems.length;i++){
   colorItems[i].onmouseover = function(){
   a = this.style.backgroundColor;
   if(a.length>7){
   a = formatRgb(a);//
   }
   colorViews.style.background = a.toUpperCase();
   colorInput.value = a.toUpperCase();
   }
   colorItems[i].onclick = function(){
   a = this.style.backgroundColor;
   if(a.length>7){
   a = formatRgb(a);//
   }
   nowColor.value = a.toUpperCase();
   pageColorViews.style.background = a.toUpperCase();
   document.body.removeChild(colorBoard);
   }
  }
  }
  //格式化函数
  function formatRgb(rgb){
  rgb = rgb.replace("rgb","");rgb = rgb.replace("(","");rgb = rgb.replace(")","");
  format = rgb.split(",");
  a = eval(format[0]).toString(16);
  b = eval(format[1]).toString(16);
  c = eval(format[2]).toString(16);
  rgb = "#"+checkFF(a)+checkFF(b)+checkFF(c);
  function checkFF(str){
   if(str.length == 1){
   str = str+""+str;
   return str;
   }else{
   return str;
   }
  }
  return rgb;
  }
  //getBody()
  function getBody(){
   var Body;
   if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
   Body = document.documentElement;
   }
   else if (typeof document.body != 'undefined') {
   Body = document.body;
   }
   return Body;
  }
  //scrollPos
  function getScrollPos(){
   var t,l;
   if (typeof window.pageYOffset != 'undefined'){
   t = window.pageYOffset;
   l = window.pageXOffset;
   }
   else{
   t = getBody().scrollTop;
   l = getBody().scrollLeft;
   }
   return {t:t,l:l};
  }
  </script>
  </head>
  <body>
  <table width="500" border="1">
   <tr>
   <td><input type="text" value="" id="nowColor" /></td>
   <td><div id="pageColorViews" style="background:#000; width:30px; height:30px;"></div></td>
   <td><a href="javascript:;" onclick="colorSelect('nowColor','pageColorViews',event)">点我就出调色板</a></td>
   </tr>
  </table>
  </body>
  </html>

调用方法:colorSelect('色值输入框ID','显示色值的容器ID',event),调用起来很简单,直接onClick就可以。 感谢:红辣椒 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]"> <html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/url]"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>调色板</title> <style> #colorBoard{position:absolute; padding:10px; width:256px; height:220px; background:#f3f3f3; border:#d9d9d9 1px solid;} #colorBank{ clear:both; border:#d9d9d9 1px solid; background:#FFF; width:252px; padding:0 0 2px 2px; overflow:hidden; margin:0 auto 0 auto;} #colorBank div{ overflow:hidden; height:12px; width:12px; margin:2px 2px 0 0; float:left; overflow:hidden; cursor:pointer;} #colorViews{width:80px; height:20px; float:left;border:#d9d9d9 1px solid; background:#000; display:block; margin: 0 10px 10px 0;} #colorInput{width:70px; height:18px; float:left; font-family:Verdana; font-size:13px; color:#333; display:block; border:none; background:#FFF;border:#d9d9d9 1px solid;margin: 0 10px 10px 0;} #colorClose{width:80px; color:#999999; height:22px; float:left;display:block; background:#f3f3f3;cursor:pointer;border:#d9d9d9 1px solid; border-top:#FFF 1px solid; border-left:#FFF 1px solid;} </style> <script> function colorSelect(now,page,e){ if(document.getElementById("colorBoard")){ return; } //关于出现位置 e=e||event; var scrollpos = getScrollPos(); var l = scrollpos.l + e.clientX; var t = scrollpos.t + e.clientY + 10; if (l > getBody().clientWidth-253){ l = getBody().clientWidth-253; } //创建DOM var nowColor = document.getElementById(now); var pageColorViews = document.getElementById(page); var ColorHex=new Array('00','33','66','99','CC','FF'); var SpColorHex=new Array('FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF'); var colorBank = document.createElement("div"); colorBank.setAttribute("id","colorBank"); var colorViews = document.createElement("div"); colorViews.setAttribute("id","colorViews"); var colorInput = document.createElement("input"); colorInput.setAttribute("id","colorInput"); colorInput.setAttribute("type","text"); colorInput.setAttribute("disabled","disabled"); var colorClose = document.createElement("input"); colorClose.setAttribute("id","colorClose"); colorClose.setAttribute("value","取消"); colorClose.setAttribute("type","button"); colorClose.onclick=function(){document.body.removeChild(colorBoard)}; var colorBoard =document.createElement("div"); colorBoard.id="colorBoard"; colorBoard.style.left = l+"px"; colorBoard.style.top = t+ "px"; colorBoard.appendChild(colorViews); colorBoard.appendChild(colorInput); colorBoard.appendChild(colorClose); colorBoard.appendChild(colorBank); document.body.appendChild(colorBoard); //循环出调色板 for(b=0;b<6;b++){ for(a=0;a<3;a++){ for(i=0;i<6;i++){ colorItem = document.createElement("div"); colorItem.style.backgroundColor="#"+ColorHex[a]+ColorHex[i]+ColorHex[b]; colorBank.appendChild(colorItem); } } } for(b=0;b<6;b++){ for(a=3;a<6;a++){ for(i=0;i<6;i++){ colorItem = document.createElement("div"); colorItem.style.backgroundColor="#"+ColorHex[a]+ColorHex[i]+ColorHex[b]; colorBank.appendChild(colorItem); } } } for(i=0;i<6;i++){ colorItem = document.createElement("div"); colorItem.style.backgroundColor="#"+ColorHex[0]+ColorHex[0]+ColorHex[0]; colorBank.appendChild(colorItem); } for(i=0;i<6;i++){ colorItem = document.createElement("div"); colorItem.style.backgroundColor="#"+ColorHex[i]+ColorHex[i]+ColorHex[i]; colorBank.appendChild(colorItem); } for(i=0;i<6;i++){ colorItem = document.createElement("div"); colorItem.style.backgroundColor="#"+SpColorHex[i]; colorBank.appendChild(colorItem); } var colorItems = colorBank.getElementsByTagName("div"); for(i=0; i<colorItems.length;i++){ colorItems[i].onmouseover = function(){ a = this.style.backgroundColor; if(a.length>7){ a = formatRgb(a);// } colorViews.style.background = a.toUpperCase(); colorInput.value = a.toUpperCase(); } colorItems[i].onclick = function(){ a = this.style.backgroundColor; if(a.length>7){ a = formatRgb(a);// } nowColor.value = a.toUpperCase(); pageColorViews.style.background = a.toUpperCase(); document.body.removeChild(colorBoard); } } } //格式化函数 function formatRgb(rgb){ rgb = rgb.replace("rgb","");rgb = rgb.replace("(","");rgb = rgb.replace(")",""); format = rgb.split(","); a = eval(format[0]).toString(16); b = eval(format[1]).toString(16); c = eval(format[2]).toString(16); rgb = "#"+checkFF(a)+checkFF(b)+checkFF(c); function checkFF(str){ if(str.length == 1){ str = str+""+str; return str; }else{ return str; } } return rgb; } //getBody() function getBody(){ var Body; if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') { Body = document.documentElement; } else if (typeof document.body != 'undefined') { Body = document.body; } return Body; } //scrollPos function getScrollPos(){ var t,l; if (typeof window.pageYOffset != 'undefined'){ t = window.pageYOffset; l = window.pageXOffset; } else{ t = getBody().scrollTop; l = getBody().scrollLeft; } return {t:t,l:l}; } </script> </head> <body> <table width="500" border="1"> <tr> <td><input type="text" value="" id="nowColor" /></td> <td><div id="pageColorViews" style="background:#000; width:30px; height:30px;"></div></td> <td><a href="javascript:;" onclick="colorSelect('nowColor','pageColorViews',event)">点我就出调色板</a></td> </tr> </table> </body> </html>

 
标签: Javascript  效果  简易  调色  
 
您可以将本页贴到其他网站
UBB代码HTML代码
 
 
 
 
手机图片下载手机图片下载手机图片下载手机图片下载手机图片下载手机图片下载更多图铃
 
 
 
 
 
 
 更多内容
 ·PHP-Javascript“返回上一页”无 ·JavaScript获取选中文本 ·悟透JavaScript ·给select控件在指定位置插入opti
 ·javascript eval() ·javascript对象与数组的例子 ·Microsoft SQL Server 2008 Expr ·选择是否恢复整个SQL Server的方
 ·微软将于11月推出Small Business ·将QQ空间音乐设置为背景音乐 ·网友QQ空间背景音乐为我所有 ·用百度MP3搜索获取自己喜欢的QQ空
 ·如何免费添加QQ空间音乐 ·Photoshop打造便条纸的粘贴效果 ·解决Windows Vista强悍的睡眠功能 ·Photoshop简单材质教程之麻织物
 ·Painter与Photoshop结合绘制清秀 ·Fireworks制作光芒四射的广告效果 ·Windows盗版提醒软件升级 醒目大 ·有技术利用Internet路由协议BGP监
 ·瑞星28日病毒播报:线上游戏窃取 ·江民28日病毒播报:"网游窃贼"窃取 ·地址簿同步功能有些什么用途? ·备份了邮箱的数据文件,如何恢复
 
 
 
最新评论  点此查看所有评论
 
 
 
 
发表评论(支持UBB码)


验证码:  
 
 
 
 
© 2005- 王朝网络 版权所有