Get size of mouse cursor in javascript

2019-06-28 03:06发布

I need to determine the width and height of the current mouse cursor used on our webpage.

I need to show a div right under the cursor, and possibly to the right of it. So I need to determine the offsets of my div from the exact pointer location, so the cursor do not cover up the div.

The mechanism will be used in intranet system, so it can be firefox-only solution. Unfortunatelly some people here use weird cursors, anyway, big ones, so I cannot just hardcode eg, 16px right, 16px top offsets. Anyway, I don't want if I don't have to.

Thanks for your help, SWilk

3条回答
beautiful°
2楼-- · 2019-06-28 03:59

I don't think this it is possible to determine any more than the cursor center within the browser. It surely can be done using a custom-made Firefox extension but I doubt there are any around for this specific task.

查看更多
姐就是有狂的资本
3楼-- · 2019-06-28 04:00

You can't do it. Anyone can set their cursor to any arbitrary garbage, and there's no API for asking from the browser.

查看更多
做自己的国王
4楼-- · 2019-06-28 04:00

While size is not possible, there are jQuery addons like SimpleTip and qTip that let you create fixed-position tool tips that don't close until something happens (like the user clicks on it). The content of the tool tips can be wrapped in divs.

查看更多
登录 后发表回答