我想用javascript / jquery获得x y像素的颜色,所以googled并发现它可以用canvas完成。
var canvas = $("<canvas>"); //Create the canvas element
//Create a layer which overlaps the whole window
canvas.css({ position: "fixed", top: "0", left: "0",
width: "100%", height: "100%", "z-index": 9001
});
//Add an event listener to the canvas element
canvas.click(function (ev) {
var x = ev.pageX, y = ev.pageY;
var canvas = this.getContext("2d");
canvas.drawWindow(window, x, y, 1, 1, "transparent");
var data = canvas.getImageData(0, 0, 1, 1).data;
var hex = rgb2hex(data[0], data[1], data[2]);
alert(hex);
$(this).remove();
});
但它无效(Firefox drawWindow
无法正常工作,也无法使用chrome)
任何想法?
答案 0 :(得分:1)
drawWindow
是a custom JavaScript implementation。您必须先包含它才能使用它。
如果您指的是the native method drawWindow(),则不能在网络内容中使用它,这就是为什么它不起作用。