views:

13

answers:

1

Hi,

I have object (div-box), and it's draggable (I'm using jQuery). How I can get information which direction it has moved a visitor? Example: User drag it to left down and I wanna know it, how?

P.S.: Sorry for my English

+1  A: 

how about this?

var start,stop;

$("#draggable2").draggable({
    axis: "x",
    start: function(event, ui) {
        start = ui.position.left;
    },
    stop: function(event, ui) {
        stop = ui.position.left;
        alert('has moved ' + ((start < stop) ? 'rigth':'left'))
    }
});​

crazy fiddle

Reigel
That's the gist of it. Implementation details may vary, but you'll have to remember where the cursor was previously and compare to where it is now. May also want to check if horizontal change was greater than vertical change to choose between left/right or up/down.
bemace
Well, this is the start of the idea. `ui.position.top` is also available. The OP can deal with it easy.
Reigel