确定事件之外的鼠标位置(使用jQuery)? [英] Determine mouse position outside of events (using jQuery)?

查看:113
本文介绍了确定事件之外的鼠标位置(使用jQuery)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用(最好)jQuery的绝对鼠标位置/坐标(X和Y),如本教程,但不在任何JavaScript事件之外。谢谢。

解决方案

不可能。但是,您可以在教程中使用相同的方法来将位置存储在全局变量中,并将其读取到事件外。



像这样:

  jQuery(document).ready(function(){
$()。mousemove(function(e){
window.mouseXPos = e.pageX;
window.mouseYPos = e.pageY;
});
})

您现在可以从任何地方使用 window.mouseXPos window.mouseYPos / p>

I need to get a hold of the absolute mouse position / coordinates (X and Y) using (preferably) jQuery like in this tutorial but outside of any JavaScript event. Thank you.

解决方案

Not possible. You can however use the same approach in the tutorial to store the position in a global variable and read it outside the event.

Like this:

jQuery(document).ready(function(){
   $().mousemove(function(e){
      window.mouseXPos = e.pageX;
      window.mouseYPos = e.pageY;
   }); 
})

You can now use window.mouseXPos and window.mouseYPos from anywhere.

这篇关于确定事件之外的鼠标位置(使用jQuery)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆