0

我在 Mozilla 中遇到 getImageData 问题。我做了一个功能,点击画布后获取鼠标坐标。坐标很好,但有一个问题,在 Mozilla 中它给 mi 错误的 getImageDatas 数字 - 例如在 chrome 中它给出 mi red: 10, green: 0, blue: 10 而 Mozilla 给出 red: 60, green: 255, blue : 10...我不知道问题出在哪里...请您帮忙吗?这是功能: http: //pastebin.com/MjnG0Nbm

4

1 回答 1

0

也许你的 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
    };        
}
于 2013-03-10T08:36:04.070 回答