Skip to main content

Search and Top Navigation

#6884 closed bug (fixed)

Opened January 20, 2011 08:57PM UTC

Closed August 17, 2014 01:30AM UTC

Last modified August 17, 2014 01:30AM UTC

Draggable: ui.offset.left differs between the "start" and "drag" hooks

Reported by: traviscooper Owned by:
Priority: minor Milestone: 1.11.2
Component: ui.draggable Version: 1.8.8
Keywords: Cc:
Blocked by: Blocking:
Description

when using the 'ui.offset.left' value with the start, drag and stop events for DRAGGABLE, you get a different value range for the start event versus the drag and stop.

For example, the following output was generated by asking for the 'ui.position.left' and ui.offset.left' for each of the events listed (start, drag, stop), as I dragged the element 1px to the right.

Notice how on the [start] event, the ui.offset.left (ui.o.l value) is "645", but for the [drag] and [start] events, the values become exactly what the ui.position.left values are (ui.p.l).

[start]--ui.p.l(247)ui.o.l(645)

[drag]--ui.p.l(248)ui.o.l(248)

[stop]--ui.p.l(248)ui.o.l(248)

From my own calculations, the above output SHOULD be.

[start]--ui.p.l(247)ui.o.l(645)

[drag]--ui.p.l(248)ui.o.l(646)

[stop]--ui.p.l(248)ui.o.l(646)

Below is my code to reproduce.

$('.element_to_move').draggable({

containment: 'parent',

cursor: 'pointer',

scroll: true,

axis: 'x' ,

grid: [1,0],

start: function(event, ui) {

// Update element data in Display

$('#er2').append('[start]--ui.p.l('+ui.position.left+')ui.o.l('+ui.offset.left+')<br />');

},

drag: function(event, ui) {

// Update element data in Display

$('#er2').append('[drag]--ui.p.l('+ui.position.left+')ui.o.l('+ui.offset.left+')<br />');

},

stop: function(event, ui){

// Update element data in Display

$('#er2').append('[stop]--ui.p.l('+ui.position.left+')ui.o.l('+ui.offset.left+')<br />');

}

});

Attachments (0)
Change History (7)

Changed January 20, 2011 08:59PM UTC by traviscooper comment:1

I'm thinking it shouldn't matter what the CSS positioning value is for the parent or element, since the initial value of the 'ui.offset.left' is correct.

Changed January 20, 2011 09:04PM UTC by traviscooper comment:2

Here is the jsbin working demo of the error.

http://jsbin.com/ilike4

Changed October 11, 2012 02:49PM UTC by scottgonzalez comment:3

milestone: 1.9.02.0.0

Changed October 26, 2012 12:30PM UTC by mikesherov comment:4

status: newopen

New demo using latest: http://jsfiddle.net/48uVM/1/ which confirms the discrepancy. It looks to be on purpose and part of the internals: https://github.com/jquery/jquery-ui/blob/039ee746d3eaeeaa4ad92ecd8ebf4e6fcd11768c/ui/jquery.ui.draggable.js#L426

However, this is not ideal, and if the internals need to rely on the "position" values provided, they should be named appropriately to signify they aren't equivalent to the common notion of position and offset.

Changed October 26, 2012 12:32PM UTC by mikesherov comment:5

summary: ui.offset.left not correct valuesDraggable: ui.offset.left differs between the "start" and "drag" hooks

Changed August 17, 2014 01:30AM UTC by Mike Sherov comment:6

resolution: → fixed
status: openclosed

Draggable: Recalculate hash offset on start after plugins run

Fixes #6884

Changeset: b5846bece34db31d69e75cb3a3537827c005910e

Changed August 17, 2014 01:30AM UTC by mikesherov comment:7

milestone: 2.0.01.11.2

Better late than never!