点击这里给我发消息 点击这里给我发消息

制作简单实用的调色板工具

添加时间:2010-1-5
    相关阅读: CSS JavaScript 制作

把如下代码加入<body>区域中:

<style type="text/CSS">
<!--
body {font:menu}
td,selcet,input { font:menu}
.memo { border: 1px #dddddd solid}
.button { border-color: #CCCCCC #666666 #666666 #CCCCCC; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
.cursorcross { cursor: crosshair}
.cursorhand { cursor: hand}
-->
</style>
<table border="0" cellspacing="1" cellpadding="3" width="350" align="center" bgcolor="#dddddd">
<tr bgcolor="#FFFFFF">
<td width="10%" align="center">
<select name="select1" onchange="selectchg(this.value)">
<option value="1" selected>红</option>
<option value="2">绿</option>
<option value="3">蓝</option>
<option value="4">灰</option>
</select>
</td>
<td width="90%" align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right">
<input type="text" name="text1" class="memo" size="10">
<input type="button" name="Button2" value=">>" class="button" onClick="choosecolor()">
</td>
<td align="right" width="3%"> </td>
<td width="30%">
<table width="40" border="0" cellspacing="1" cellpadding="0" height="20" class="cursorcross">
<tr>
<td id="customcolor" bgcolor="#FFFFFF" onMouseOver="showcolor(this)"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="10%" align="center">
<table id="tableleft" border="0" cellspacing="1" cellpadding="0" class="cursorhand">
<script language="VBScript">
function hexit(which)
hexit=hex(which)
end function
</script>
<script language="JavaScript">
for(i=0;i<=15;++i)
{document.write('<tr><td align="center">'+ hexit(0+i*17) +'</td><td id="tdleft' + i +'" bgcolor="rgb('+ (0+i*17) + ',0,0)" width="15" height="15" onclick="changeright(this.num)" onmouseover="showcolor(this)"></td></tr>')
document.all['tdleft' + i].num=i
}
</script>
</table>
</td>
<td align="center" width="90%">
<table id="tableleft" border="0" cellspacing="1" cellpadding="0" class="cursorcross">
<script language="JavaScript">
document.write('<tr><td></td>')
for(i=0;i<=15;++i)
{document.write('<td align="center">'+ hexit(0+i*17) +'</td>')}
document.write('</tr>')

for(i=0;i<=15;++i)
{document.write('<tr>')
document.write('<td align="center">'+ hexit(0+i*17) +'</td>')
for(j=0;j<=15;++j)
{document.write('<td id="tdrightr' + i + 'c' + j +'" bgcolor="rgb(0,'+ (0+i*17) + ',' + (0+j*17) + ')" width="15" height="15" onmouseover="showcolor(this)" onclick="clickright(this)"></td>')}
document.write('</tr>')
}

</script>
</table>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2" height="20">·可选16*16*16种颜色。<br>
·单击左边的颜色会得到更多的颜色。<br>
·单击右边的颜色会固定选取的颜色。 <br>
·输入框可以自定义颜色。</td>
</tr>
</table>
<script language="JavaScript">
function selectchg(which)
{switch(which)
{case '1' :leftR();break;
case '2' :leftG();break;
case '3' :leftB();break;
case '4' :leftA();break;
}
}
function leftR()
{for(i=0;i<=15;++i)
{document.all['tdleft'+i].bgColor='rgb('+ (0+i*17) + ',0,0)'}
rightR(0)
}
function leftG()
{for(i=0;i<=15;++i)
{document.all['tdleft'+i].bgColor='rgb(0,'+ (0+i*17) + ',0)'}
rightG(0)
}
function leftB()
{for(i=0;i<=15;++i)
{document.all['tdleft'+i].bgColor='rgb(0,0,'+ (0+i*17) + ')'}
rightB(0)
}
function leftA()
{for(i=0;i<=15;++i)
{document.all['tdleft'+i].bgColor='rgb('+ (0+i*17) + ','+ (0+i*17) + ','+ (0+i*17) + ')'}
rightA()
}
function rightR(which)
{for(i=0;i<=15;++i)
{for(j=0;j<=15;++j)
{document.all['tdrightr' + i + 'c' + j].bgColor='rgb(' + (0+which*17) + ',' + (0+i*17) + ','+ (0+j*17) + ')'}
}
}
function rightG(which)
{for(i=0;i<=15;++i)
{for(j=0;j<=15;++j)
{document.all['tdrightr' + i + 'c' + j].bgColor='rgb(' + (0+i*17) + ',' + (0+which*17) + ',' + (0+j*17) + ')'}
}
}
function rightB(which)
{for(i=0;i<=15;++i)
{for(j=0;j<=15;++j)
{document.all['tdrightr' + i + 'c' + j].bgColor='rgb(' + (0+i*17) + ','+ (0+j*17)+ ',' + (0+which*17) + ')'}
}
}
function rightA()
{for(i=0;i<=15;++i)
{for(j=0;j<=15;++j)
{document.all['tdrightr' + i + 'c' + j].bgColor='rgb(' + (0+i*16+j) + ','+ (0+i*16+j)+ ',' + (0+i*16+j) + ')'}
}
}
var rightclicked=false
function clickright(which)
{if(rightclicked){rightclicked=false;showcolor(which)}else{rightclicked=true}
}
function changeright(which)
{switch(select1.value)
{case '1' :rightR(which);break;
case '2' :rightG(which);break;
case '3' :rightB(which);break;
}
}
function showcolor(which)
{if(rightclicked)return;
text1.value=which.bgColor
choosecolor()
}
function choosecolor()
{customcolor.bgColor=text1.value
}
</script>

本文作者:
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册