wokena wokena - 1 year ago 113
jQuery Question

How to get the direction of moving object in draggable plugin (jQuery)?

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

Answer Source

how about this?

var start,stop;

    axis: "x",
    start: function(event, ui) {
        start = ui.position.left;
    stop: function(event, ui) {
        stop = ui.position.left;
        alert('has moved ' + ((start < stop) ? 'right':'left'))

crazy fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download