日期:2014-05-16 浏览次数:20356 次
var drawing = document.getElementById("drawing");//div层#content中的canvas
if(drawing.getContext){
var context = drawing.getContext("2d");
var btn_select_color = document.createElement("input");
btn_select_color.type = "button";
btn_select_color.value = "打开调色板看看?";
var btn_close_board = document.createElement("input");
btn_close_board.type = "button";
btn_close_board.value = "关闭调色板";
var content = document.getElementById("content");//div层#content
content.appendChild(btn_select_color);
content.appendChild(btn_close_board);
function drawBoard(){
for(var i = 0;i < 6;i++){
for(var j = 0;j < 6;j++){
context.fillStyle = "rgb(0,"+Math.floor(255-i*42.5)+
","+Math.floor(255-j*24.5)+")";
context.fillRect(i*20,j*20,20,20);
}
}
}
function closeBoard(){
context.clearRect(0,0,120,120);
}
EventUtil.addHandler(btn_select_color,"click",drawBoard);
EventUtil.addHandler(btn_close_board,"click",closeBoard);
}