tags:

views:

11

answers:

1

Hi, is it possible to change the left position of a div after dropping it? i'm trying to do that using this code but it's not working, can anybody help me... thanks a million in advance :)

$(function () {
           $("#task_1").draggable({ revert: 'invalid' });
           $("#Lina").droppable({
               drop: function (ev, ui) {
                   var pos = $("#task_1").position();
                   //                   kolla(pos.left);
                   if (pos.left < 0) {
                       alert(pos.left);
                       $("#task_1").position().left = 0;
                   }
                   else {
                       // do something else
                   }
               }
           });

       });
A: 

Just a quick idea, have you tried:

 $("#task_1").css("left","0");

If the outer drop-area has relative positioning (not sure, have to check) that should work.

Basically, you want the dropped div to shift to the very left of the drop area, right?

Update

You have it so that the position is changed when the condition is pos < 0. Since the div won't be in the drop-area if it's outside of it, I think you mean pos > 0. Also, why bother checking, if it's already 0, it just changes it to what it already is.

For instance:

$(function () {
           $("#task_1").draggable({ revert: 'invalid' });
           $("#Lina").droppable({
               drop: function (ev, ui) {
                       this.position().left = 0;
               }
           });

       });

Notice I also made it "this" since you are changing the selector.

Anthony