我如何确定光标是否在元素的范围内 [英] how do I find out if the cursor is in the bounds of an element

查看:77
本文介绍了我如何确定光标是否在元素的范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个拖放应用程序,我想做的是当用户拖动某个元素时,如果光标在某个其他元素上,则会得到

I'm creating a drag and drop application and what I want to do is while the user is dragging an element get if the cursor is over certain other element.

这里有流程:

用户开始在页面上拖动元素
当鼠标移过某些部分时,我想进行ajax调用.

User starts dragging an element around the page
When the mouse gets over certain parts I want to make an ajax call.

因为我通过jquery知道元素及其边界,所以我只想要最好的检查方法.

Because I know the elements and their bounds via jquery I just want the best way to make the check.

推荐答案

从此处开始: http://docs .jquery.com/Tutorials:Mouse_Position

获取鼠标坐标并将其与您要比较的项目的.offset()值进行比较.

Get the mouse coordinates and compare it to the .offset() values of the item you're comparing it to.

http://api.jquery.com/offset/

这篇关于我如何确定光标是否在元素的范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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