栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

javascript实现根据3原色制作颜色选择器的方法

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

javascript实现根据3原色制作颜色选择器的方法

本文实例讲述了javascript实现根据3原色制作颜色选择器的方法。分享给大家供大家参考。具体如下:

document.write('');
T={s:true};
T.a=A.$('msecolor_ab2').children[0];
T.b=A.$('msecolor_ab2').children[1];
T.c=A.$('msecolor_ac1');
T.d=A.$('msecolor_ac2');
T.ini=function(id,fun){
 this.fun=fun;
 if(typeof(id)!='object')
 id=A.$(id);
 this.obj=id;
 var w=A.wz(id);
 var ph=document.documentElement.clientHeight,pw=document.documentElement.clientWidth;
 var sh=document.documentElement.scrollTop,sw=document.documentElement.scrollLeft;
 if(w.x-sw+322 > pw){
  var l=w.x+id.offsetWidth - 322;
 }else{
  var l=w.x;
 }
 if(w.y-sh+329+id.offsetHeight > ph){
  var t=w.y - 329;
 }else{
  var t=w.y+id.offsetHeight;
 }
 with(A.$('msecolor').style){
  display='block';
  top=t+'px';
  left=l+'px';
 }
}
T.hide=function(){A.$('msecolor').style.display='none';}
T.e=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'];
T.f=function(a){
 T.h=a;
 T.c.innerHTML='';
 if(a==7){
  for(var i=0;i<16;i++){
  var s=A.$$('span');
  s.title=s.style.backgroundColor='#'+T.e[i]+T.e[i]+T.e[i]+T.e[i]+T.e[i]+T.e[i];
  T.c.appendChild(s);
  }
  T.g(a,0);
 }else{
 for(var i=0;i<16;i++){
 var s=A.$$('span');
 s.title=s.style.backgroundColor=T.z(a,T.e[i]);
 T.c.appendChild(s);
 s.onclick=function(){
  var s=this.title.substr(1,1);
  if(s=='0')
  s=this.title.substr(3,1);
  if(s=='0')
  s=this.title.substr(5,1);
  T.g(T.h,s);
  }
 }
 T.g(a,0);
 }
}
T.g=function(a,b){
 T.d.innerHTML='';
 switch(parseInt(a)){
  case 1:
  var c=3,e=5,g='T.z(a,b,c,T.e[parseInt(i/16)],e,T.e[i%16])';
  break;
  case 3:
  var c=1,e=5,g='T.z(c,T.e[parseInt(i/16)],a,b,e,T.e[i%16])';
  break;
  case 5:
  var c=1,e=3,g='T.z(c,T.e[parseInt(i/16)],e,T.e[i%16],a,b)';
  break;
  case 7:
  for(var i=0;i<256;i++){
   var s=document.createElement('span');
   s.title=s.style.backgroundColor='#'+T.e[parseInt(i/16)]+T.e[i%16]+T.e[parseInt(i/16)]+T.e[i%16]+T.e[parseInt(i/16)]+T.e[i%16];
   s.onmouseover=function(){
    T.a.value=this.title;
    T.b.style.backgroundColor=this.style.backgroundColor;
    T.b.title=this.title;
   }
   s.onclick=function(){
    T.hide();
    T.fun(this.title,T.obj);
   }
   T.d.appendChild(s);
  }
  return false;
  break;
 }
 for(var i=0;i<256;i++){
 var s=document.createElement('span');
 s.title=s.style.backgroundColor=eval(g);
 s.onmouseover=function(){
  T.b.style.backgroundColor=this.style.backgroundColor;
  T.a.value=this.title;
  T.b.title=this.title;
 }
 s.onclick=function(){
  T.hide();
  T.fun(this.title,T.obj);
 }
 T.d.appendChild(s);
 }
}
T.b.onclick=function(){
 T.hide();
 T.fun(this.title,T.obj);
}
T.a.onkeyup=function(e){
 var e=e || event;
 if(e.keyCode==13){
  T.b.style.backgroundColor=this.value;
  T.b.title=this.value;
  T.hide();
  T.fun(this.value,T.obj);
 }
}
T.z=function(a,b,c,d,e,f){s='#';a=parseInt(a);c=parseInt(c);e=parseInt(e);for(var i=0;i<6;i++){if(i>=(a-1) && i<(a+1)){s+=b;}else if(i>=(c-1) && i<(c+1)){s+=d;}else if(i>=(e-1) && i<(e+1)){s+=f;}else{s+='0';}}return s;}
T.f(1);

运行效果图如下:

希望本文所述对大家的javascript程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/101603.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号