人生本是一个不断学习的过程,在这个过程中,图老师就是你们的好帮手,下面分享的Javascript简易调色板效果懂设计的网友们快点来了解吧!
【 tulaoshi.com - Web开发 】
调用方法:colorSelect('色值输入框ID','显示色值的容器ID',event),调用起来很简单,直接onClick就可以。 感谢:红辣椒
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)!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"
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title调色板/title
style
#colorBoard{position:absolute; padding:10px; width:256px; height:220px; background:#f3f3f3; border:#d9d9d9 1px solid;}
#colorBank{ clear:both; border:#d9d9d9 1px solid; background:#FFF; width:252px; padding:0 0 2px 2px; overflow:hidden; margin:0 auto 0 auto;}
#colorBank div{ overflow:hidden; height:12px; width:12px; margin:2px 2px 0 0; float:left; overflow:hidden; cursor:pointer;}
#colorViews{width:80px; height:20px; float:left;border:#d9d9d9 1px solid; background:#000; display:block; margin: 0 10px 10px 0;}
#colorInput{width:70px; height:18px; float:left; font-family:Verdana; font-size:13px; color:#333; display:block; border:none; background:#FFF;border:#d9d9d9 1px solid;margin: 0 10px 10px 0;}
#colorClose{width:80px; color:#999999; height:22px; float:left;display:block; background:#f3f3f3;cursor:pointer;border:#d9d9d9 1px solid; border-top:#FFF 1px solid; border-left:#FFF 1px solid;}
/style
script
function colorSelect(now,page,e){
if(document.getElementById("colorBoard")){
return;
}
//关于出现位置
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
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","取消");
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);
//循环出调色板
for(b=0;b6;b++){
for(a=0;a3;a++){
for(i=0;i6;i++){
colorItem = document.createElement("div");
colorItem.style.backgroundColor="#"+ColorHex[a]+ColorHex[i]+ColorHex[b];
colorBank.appendChild(colorItem);
}
}
}
for(b=0;b6;b++){
for(a=3;a6;a++){
for(i=0;i6;i++){
colorItem = document.createElement("div");
colorItem.style.backgroundColor="#"+ColorHex[a]+ColorHex[i]+ColorHex[b];
colorBank.appendChild(colorItem);
}
}
}
来源:http://www.tulaoshi.com/n/20160219/1623910.html
看过《Javascript简易调色板效果》的人还看了以下文章 更多>>