Aufrufmethode: colorSelect('ID des Farbwert-Eingabefelds', 'Container-ID, die den Farbwert anzeigt', Ereignis), der Aufruf ist sehr einfach, nur ein Klick. Danke an: Red Pepper
<!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 ">
<Kopf>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Palette</title>
<Stil>
#colorBoard{position:absolute; padding:256px; height:#d9d9d9 1px solid;}
#colorBank{ clear:both; border:#d9d9d9 1px solid; width:252px;
#colorBank div{ overflow:hidden; width:12px; float:overflow:pointer;}
#colorViews{width:80px; height:20px; float:left;border:#d9d9d9 1px solid;display:block:0 10px 10px 0;}
#colorInput{width:70px; float:left; font-size:#333; background:#d9d9d9 solide;Rand: 0 10px 10px 0;}
#colorClose{width:80px; height:22px;display:block;background:#d9d9d9 1px solid;#FFF 1px solid; -left:#FFF 1px solide;}
</style>
<Skript>
Funktion colorSelect(now,page,e){
if(document.getElementById("colorBoard")){
zurückkehren;
}
//Über die Erscheinungsposition
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 erstellen
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","Cancel");
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);
//Schleifen Sie die Palette aus
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);
}
}
}
//Formatfunktion
FunktionsformatRgb(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);
Funktion checkFF(str){
if(str.length == 1){
str = str+""+str;
return str;
}anders{
return str;
}
}
rgb zurückgeben;
}
//getBody()
Funktion getBody(){
varBody;
if (typeof document.compatMode != 'undefiniert' && document.compatMode != 'BackCompat') {
Body = document.documentElement;
}
else if (typeof document.body != 'undefiniert') {
Body = document.body;
}
Rückkehr Körper;
}
//scrollPos
Funktion getScrollPos(){
var t,l;
if (typeof window.pageYOffset != 'undefiniert'){
t = window.pageYOffset;
l = window.pageXOffset;
}
anders{
t = getBody().scrollTop;
l = getBody().scrollLeft;
}
return {t:t,l:l};
}
</script>
</head>
<Körper>
<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)">Klicken Sie auf mich und die Palette wird angezeigt</a></td>
</tr>
</table>
</body>
</html>