首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mozilla getImageDataProblem

Mozilla getImageDataProblem
EN

Stack Overflow用户
提问于 2013-03-09 20:31:54
回答 1查看 58关注 0票数 0

我对Mozilla中的getImageData有问题。我做了一个函数,点击画布后得到鼠标的坐标。坐标是好的,但问题是,在Mozilla中,它给了mi错误的getImageDatas数字-例如,在chrome中,它给了mi红色: 10,绿色: 0,蓝色: 10,而Mozilla给出了红色: 60,绿色: 255,蓝色:10……我不知道问题出在哪里。求求你,你能帮忙吗?下面是函数:http://pastebin.com/MjnG0Nbm

EN

回答 1

Stack Overflow用户

发布于 2013-03-10 16:36:04

也许您的getMousePos()并不总是给出想要的结果

代码语言:javascript
复制
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.

试着这样做:

代码语言:javascript
复制
function getMousePosition(canvas, evt) {
    return {
      x: evt.clientX - canvas.offsetLeft + window.scrollX,
      y: evt.clientY - canvas.offsetTop + window.scrollY
    };        
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15310691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档