When I drag an element over another div on which I have a mouseover event, the event doesn’t trigger. However, it works if I hover over it without dragging.
Is there a way to detect hover events on an element if I drag another one over it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is an example using the X-Y coordinate solution.
Working example on jsfiddle
The example can be improved, but is a good starting point.
Simply keeps track of the mouse location and checks if it appears to be inside any bounding boxes of the droppable objects. Hence, if the mouseup event fires on any one of them, dragged object is dropped.
You can also use the coordinates of the object you are dragging for detecting if its on a droppable box, but it requires a little more code for finding the bounding box coords and using the mouse is enough for me.
The code uses jQuery but no jQueryUI.
I tested in Chrome, Firefox and Opera, but not IE 🙂
I’m also adding the code to here if jsfiddle is not accessible.
HTML
CSS
JS