Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript mouseover while dragging

I'm trying to implement a drag and drop script and have hit the wall with one problem. When you take an item and start dragging it - the item is directly below your cursor and onmouseover event is very rarely fired on the items below. But i want other items to highlight when i drag something over them. One of the solutions would be not to drag anything at all - that way the mouse events would work, but that would look ugly. Has anyone ever done something like this and know how to overcome this problem?

If you're thinking about suggesting some JQuery plugin or something like that - please don't. I don't need a completed solution, this is educational.

like image 963
Marius Avatar asked Dec 21 '10 07:12

Marius


Video Answer


1 Answers

IMO, in order to have the mouseover event to be fired up frequently would be binding the mouseover event to the parent element of all the affected elements, or perhaps to the document itself, since events get bubbled up, they are probably the only elements that can fire the mouseover events.

Then further, write a hit method in your mouseover event and actively check the position of your mouse cursor, see whether it's going under the target element's boundary. Tradeoff in usability and performance. You choose.

My 2cents.

Or perhaps, you can reverse engineer jQuery UI to see how they implement the drag element. Haven't check thou, but I think there should be a wiser way.

like image 115
Lionel Chan Avatar answered Oct 25 '22 21:10

Lionel Chan