liweshou 岁月如歌
贵有恒,何必三更起,五更眠。 最无益,只怕一日暴,十日寒!

一个不错的颜色拾取器,原来只支持ie

修改了一下,支持FF了

 

<HTML>
<HEAD>
<TITLE>WColor3</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE type=text/css>TD {
 FONT-SIZE: 9pt
}
BODY {
 FONT-SIZE: 10.8pt
}
BUTTON {
 FONT-SIZE: 12px; WIDTH: 5em
}
A {
 COLOR: blue
}
</STYLE>

<SCRIPT language=JavaScript>


var SelRGB = '';
var DrRGB = '';
var SelGRAY = '120';


var hexch = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');

// initColor() function added by Macro Zeng
// 2006-7-26   http://www.hbcms.com
function initColor() {
 if ( location.search != '' && location.search != '?' ) {
  var old_color = location.search.substr(1);
  if ( /^[0-9A-Fa-f]{6}$/.test(old_color) ) {
   SelRGB = '#'+old_color;
   RGB.innerText = SelRGB;
   EndColor();
  } else {
   SelColor.value = old_color;
   ShowColor.bgColor = SelColor.value;
  }
 }
}


function ToHex(n)
{ var h, l;

 n = Math.round(n);
 l = n % 16;
 h = Math.floor((n / 16)) % 16;
 return (hexch[h] + hexch[l]);
}

function DoColor(c, l)
{ var r, g, b;

  r = '0x' + c.substring(1, 3);
  g = '0x' + c.substring(3, 5);
  b = '0x' + c.substring(5, 7);
 
  if(l > 120)
  {
    l = l - 120;

    r = (r * (120 - l) + 255 * l) / 120;
    g = (g * (120 - l) + 255 * l) / 120;
    b = (b * (120 - l) + 255 * l) / 120;
  }else
  {
    r = (r * l) / 120;
    g = (g * l) / 120;
    b = (b * l) / 120;
  }

  return '#' + ToHex(r) + ToHex(g) + ToHex(b);
}

function EndColor()
{ var i;

  if(DrRGB != SelRGB)
  {
    DrRGB = SelRGB;
    for(i = 0; i <= 30; i ++)
      GrayTable.rows(i).bgColor = DoColor(SelRGB, 240 - i * 8);
  }

 if ( RGB.innerText == '') {
  initColor();
 } else {
   SelColor.value = DoColor(RGB.innerText, GRAY.innerText);
   ShowColor.bgColor = SelColor.value;
 }
}
</SCRIPT>
<script language="JavaScript" type="text/javascript">
 function CT_onclick(o)
 {
  //alert(o.bgColor);
  //SelRGB = event.srcElement.bgColor;
  SelRGB=o.bgColor;
   EndColor();
 }
 function CT_ondblclick(o)
 {
   // 不用再按确定了
  // 2006-7-26 added by http://www.hbcms.com
    //window.returnValue = SelColor.value;
  parent.document.getElementById('CoDiv').style.display="none";
  parent.document.getElementById('inputColor').value=SelColor.value; 
   //window.close();
  
 }
 function CT_onmouseover(o)
 {
   // RGB.innerText = event.srcElement.bgColor;
    RGB.innerText = o.bgColor;
     EndColor();
   // alert(o);
 }
 function CT_onmouseout(o)
 {
    RGB.innerText = SelRGB;
     EndColor();
 }
 ///----------------------
  function GT_onclick(o)
 {
  //SelGRAY = event.srcElement.title;
  SelGRAY = o.title;
    EndColor();
 
    window.returnValue = SelColor.value;
   window.close();
 }
 function GT_ondblclick(o)
 {
   // 不用再按确定了
  // 2006-7-26 added by http://www.hbcms.com
    window.returnValue = SelColor.value;
   window.close();
  
 }
 function GT_onmouseover(o)
 {
 //GRAY.innerText = event.srcElement.title;
 GRAY.innerText = o.title;
 EndColor();
 }
 function GT_onmouseout(o)
 {
   GRAY.innerText = SelGRAY;
     EndColor();
 }
 function OK_onclick(o)
 {
  window.returnValue = SelColor.value;
    window.close();
 }
 function HideDiv()
 {
  parent.document.getElementById('CoDiv').style.display="none";
  
 }
</script>
<BODY><SPAN id=hbcms_select_color>
<DIV align=center>
<CENTER>
<TABLE cellSpacing=10 cellPadding=0 border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE id=ColorTable  style="CURSOR: hand" cellSpacing=0 cellPadding=0
      border=0>
        <SCRIPT language=JavaScript>
function wc(r, g, b, n)
{
 r = ((r * 16 + r) * 3 * (15 - n) + 0x80 * n) / 15;
 g = ((g * 16 + g) * 3 * (15 - n) + 0x80 * n) / 15;
 b = ((b * 16 + b) * 3 * (15 - n) + 0x80 * n) / 15;

 document.write('<TD onClick="CT_onclick(this)"   ondblclick="CT_ondblclick(this)" onmouseover="CT_onmouseover(this)" onmouseout="CT_onmouseout(this)" BGCOLOR=#' + ToHex(r) + ToHex(g) + ToHex(b) + ' height=8 width=8></TD>');
}

var cnum = new Array(1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0);

  for(i = 0; i < 16; i ++)
  {
     document.write('<TR>');
     for(j = 0; j < 30; j ++)
     {
      n1 = j % 5;
      n2 = Math.floor(j / 5) * 3;
      n3 = n2 + 3;

      wc((cnum[n3] * n1 + cnum[n2] * (5 - n1)),
       (cnum[n3 + 1] * n1 + cnum[n2 + 1] * (5 - n1)),
       (cnum[n3 + 2] * n1 + cnum[n2 + 2] * (5 - n1)), i);
     }

     document.writeln('</TR>');
  }
</SCRIPT>

 <TBODY></TBODY></TABLE></TD>
    <TD>
      <TABLE id=GrayTable style="CURSOR: hand" cellSpacing=0 cellPadding=0
      border=0>
        <SCRIPT language=JavaScript>
  for(i = 255; i >= 0; i -= 8.5)
     document.write('<TR BGCOLOR=#' + ToHex(i) + ToHex(i) + ToHex(i) + '><TD  onclick="GT_onclick(this)" ondblclick="GT_ondblclick(this)" onmouseover="GT_onmouseover(this)" onmouseout="GT_onmouseout(this)" TITLE=' + Math.floor(i * 16 / 17) + ' height=4 width=20></TD></TR>');
</SCRIPT>

        <TBODY></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER></DIV>
<DIV align=center>
<CENTER>
<TABLE cellSpacing=10 cellPadding=0 border=0>
  <TBODY>
  <TR>
    <TD align=center rowSpan=2><!--选中色彩 -->
      <TABLE id=ShowColor height=30 cellSpacing=0 cellPadding=0 width=50
      border=1>
        <TBODY>
        <TR>
          <TD></TD></TR></TBODY></TABLE><!-- // 2006-7-26 added by http://www.hbcms.com --><BUTTON
      style="FONT-SIZE: 9pt; WIDTH: 50px; HEIGHT: 20px" onfocus=blur();
      onclick=initColor();>恢复</BUTTON> </TD>
    <TD rowSpan=2><!-- // 2006-7-26 added by http://www.hbcms.com --><!--FONT
      title=点击查看详细帮助 style="CURSOR: hand"
      onclick='alert("选色使用技巧:\n\n1.双击颜色 或 单击颜色,微调亮度,点确定\n\n2.色彩亮度微调:在右边竖立的颜色条中进行\n");'>帮助:
      选色技巧</FONT> <BR-->基色: <SPAN id=RGB></SPAN><BR>亮度: <SPAN
      id=GRAY>120</SPAN><BR>代码: <INPUT id=SelColor
      style="FONT-SIZE: 9pt; HEIGHT: 20px" size=7></TD>
    <TD><BUTTON id=Ok onClick="OK_onclick()" type=submit>确定</BUTTON></TD></TR>
  <TR>
    <TD><BUTTON
onclick=window.close();>取消</BUTTON></TD></TR></TBODY></TABLE></CENTER></DIV></SPAN>
<SCRIPT language=JavaScript>
<!--
// 初始化传递过来的颜色
// 2006-7-26 added by http://www.hbcms.com/
initColor();
//-->
</SCRIPT>
<SPAN id=select_color_desc>
</SPAN>

</BODY></HTML>

posted on 2008-09-02 13:42  飞阿飞  阅读(1047)  评论(0编辑  收藏  举报