我对Mozilla中的getImageData有问题。我做了一个函数,点击画布后得到鼠标的坐标。坐标是好的,但问题是,在Mozilla中,它给了mi错误的getImageDatas数字-例如,在chrome中,它给了mi红色: 10,绿色: 0,蓝色: 10,而Mozilla给出了红色: 60,绿色: 255,蓝色:10……我不知道问题出在哪里。求求你,你能帮忙吗?下面是函数:http://pastebin.com/MjnG0Nbm
发布于 2013-03-10 16:36:04
也许您的getMousePos()并不总是给出想要的结果
The amount of scrolling that has been done of the viewport area (or any other
scrollable element) is taken into account when computing the bounding rectangle.
This means that the top and left property change their values as soon as the
scrolling position changes (so their values are relative to the viewport and not
absolute). If this is not the desired behaviour just add the current scrolling
position to the top and left property (via window.scrollX and window.scrollY) to
get constant values independent from the current scrolling position.试着这样做:
function getMousePosition(canvas, evt) {
return {
x: evt.clientX - canvas.offsetLeft + window.scrollX,
y: evt.clientY - canvas.offsetTop + window.scrollY
};
}https://stackoverflow.com/questions/15310691
复制相似问题