Berikut ialah kod sumber yang memerlukan pelayar untuk menyokong html5
< ;html>
acara)">
< ;/canvas>
if(document.createElement("canvas")){
if(document.getElementById("colorPicker").getContext){
var can = document.getElementById( "colorPicker");
can .setAttribute("height",300);
var cxt = can.getContext("2d"); ;
gradient.addColorStop(0 ,'#00ff00');
gradient.addColorStop(1,'#ff0000'); ,60,200);
var ox = can.offsetLeft
var oy = can.offsetTop;
var span = document.createElement("input"); rgba");
dokumen. getElementById("textResult").appendChild(span);
}
}
function showCurrentColor(e){
var x = e.clientX - 8;
var y = e.clientY - 29;
var w = 10;
if(document.createElement("kanvas")){
if(document.getElementById("colorPicker").getContext ){
var can = document .getElementById("colorPicker");
var cxt = can.getContext("2d"); 🎜>var span = document.getElementById( "rgba");
var imgDatas = cxt.getImageData(ox,oy,10,200); *(w)*(y) ( x)*4 1];
var r = imgData[4 *(w)*(y) (x)*4]; (w)*(y) (x )*4 2];
var a = imgData[4 *(w)*(y) (x)*4 3]; " r " g=" g " b =" b " a=" a;
document.getElementById("textResult").appendChild(span);
}
}
}
< ;/body>