0

Possible Duplicate:
Body scroll with mouse position?

I am currently working on a website that revolves around the idea of a cartoon room, and the user clicks on different objects in the room to bring up information. However, I have made the room a specific amount of pixels and sometimes it is too big for a certain resolution, thereby causing scroll bars. I was wondering if there is some javascript/jquery that could follow the mouse cursor so that as the user moves around the room, the whole room moves around with them, and the scroll bars can be hidden. Any ideas what could do this?

4

1 回答 1

1

你当然可以。问题是你是否应该这样做。

你需要css:

body, html {
  overflow: hidden;
}

然后你监听 mousemove 事件。示例:javascript onmousemove 获取相对坐标

然后相应地调整 document.body.scrollTop 和 document.body.scrollLeft。

这是一个 jQuery 示例:Body scroll with mouse position?

另一个例子:正确使用onmousemove

于 2012-08-23T23:40:45.833 回答