tags:

views:

20

answers:

2

I'm making a drag and drop action, and I want an element to shift down when I bring an element over the one that is in my way.

A: 

a simple hack would be to say something like:

var hoverElem = null;
$('*').hover(function() {hoverElem = this});

then when you need to call what ever function to get the value, just use hoverElem

Jeremy
Instead of attaching a mouse handler to every element (which also fires on `mouseleave` you should use `$('*').live('mouseenter', function() { hoverEleme = this; });`, it's a *lot* cheaper, especially the more elements you get.
Nick Craver
duly noted. i figured hover only did mouseenter when there was just the first function in the call.
Jeremy
A: 

I don't know if there is a standard way, but I would probably bind a "mouseover" event to all the elements you might want to move down if you are over them and then test to see if you are currently dragging an object.

Again, i don't really know your exact setup, but you could have a global variable var currentlyDragging = false then when you start dragging set it to true. Then when you mouse over an element you want to move out of your way you can test to see if your currentyDragging variable is true and if it is then you can move it.

Bit complicated, but I can't really think of any other way of doing it off the top of my head. :)

Thomas Clayson