Jsn
Jsn

Reputation: 73

jQuery draggable element changes position on drag start when position is absolute

when I click on the item and start dragging it, it changes it's initial position on drag start. The elements have "left" and "top" properties in the style attribute. This happens when they have absolute position.

enter image description here

and the jquery: it was initially this: $('.tree li').draggable();

I also tried this:

$('.tree li').draggable({
  containment: '.tree',
    snap: '.tree',
    start: function (event, ui) {
      if ($(event.target).is('.ui-draggable-dragging')) {
          var x = $(event.target).offset().left;
          var y = $(event.target).offset().top;
          $(this).css({
              'left': x,
              'top': y
          });
        }
      }
});

the containers are relative, only the list items are absolute. When the itemst are listed, they have style attributes with positions set. When I click an item, at the very beginning it changes it''s position and start dragging from the changed position instead of dragging from the position when I click on it.

Here is a fiddle: https://jsfiddle.net/oe2955m5/

Upvotes: 1

Views: 1653

Answers (1)

Jsn
Jsn

Reputation: 73

It's because of the scale property of the parent container. When I remove the scale they move as they are supposed to move.

Upvotes: 1

Related Questions