您好,欢迎访问一九零五行业门户网

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

本文实例讲述了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=(a-1) && i=(c-1) && i=(e-1) && i<(e+1)){s+=f;}else{s+='0';}}return s;}t.f(1);
运行效果图如下:
希望本文所述对大家的javascript程序设计有所帮助。
其它类似信息

推荐信息