如何知道什么元素是当前的鼠标位置? [英] How to know what elements are in current mouse position?

查看:94
本文介绍了如何知道什么元素是当前的鼠标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道当前鼠标位置的元素,我正在使用jQuery。

I need know what elements are in current mouse position and I'm using jQuery.

推荐答案

你需要找出鼠标当前所在的元素。如果这是正确的,你可以使用

If I understood you correctly you need to find out the element over the mouse is currently on. If this is correct you can use

document.elementFromPoint ( x, y );

document.elementFromPoint


从文档
返回elementFromPoint方法是
调用,它是位于给定点下面的最高元素

点通过坐标指定,在
CSS像素中,相对于
窗口中最左上角的点或
框架包含文档。

Returns the element from the document whose elementFromPoint method is being called which is the topmost element which lies under the given point. The point is specified via coordinates, in CSS pixels, relative to the upper-left-most point in the window or frame containing the document.



$(document).ready(function(){
   $(this).mousemove(function(e){
      var elem = document.elementFromPoint ( e.pageX , e.pageY );
    alert ( elem.id );
   }); 
})

这篇关于如何知道什么元素是当前的鼠标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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