Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#15021 closed bug (fixed)

JQuery UI Sortable : get wrong top and left in function _getParentOffset

Reported by: zudar Owned by: Scott González
Priority: minor Milestone: 1.12.2
Component: ui.sortable Version: 1.11.3
Keywords: Cc:
Blocked by: Blocking:

Description

in function _getParentOffset

if(this.cssPosition === "absolute" && this.scrollParent[0] !== this.document[0] && $.contains(this.scrollParent[0], this.offsetParent[0])) {
			po.left += this.scrollParent.scrollLeft();
			po.top += this.scrollParent.scrollTop();
		}

After I sort the elements frist time. "this.cssPosition" always equals "absolute",When I sort the elements next time , get wrong top and left.

I update with follow code.The "helper" get the right position.

if(this.helper.css("position", "absolute") === "absolute" && this.scrollParent[0] !== this.document[0] && $.contains(this.scrollParent[0], this.offsetParent[0])) {
			po.left += this.scrollParent.scrollLeft();
			po.top += this.scrollParent.scrollTop();
		}

Change History (3)

comment:1 Changed 7 years ago by typytype

another option might be to move the assignment of this.cssPosition in _mouseStart above the code that calls the _getParentOffset method. I imagine this might solve some potential issues with _getRelativeOffset which also makes use of this.cssPosition which is currently undefined the first time you drag.

//The element's absolute position on the page minus margins
		this.offset = this.currentItem.offset();
		this.offset = {
			top: this.offset.top - this.margins.top,
			left: this.offset.left - this.margins.left
		};

                // Only after we got the offset, we can change the helper's position to absolute
		// TODO: Still need to figure out a way to make relative sorting possible
		this.helper.css( "position", "absolute" );
		this.cssPosition = this.helper.css( "position" );

		$.extend( this.offset, {
			click: { //Where the click happened, relative to the element
				left: event.pageX - this.offset.left,
				top: event.pageY - this.offset.top
			},
			parent: this._getParentOffset(),

			// This is a relative to absolute position minus the actual position calculation -
			// only used for relative positioned helper
			relative: this._getRelativeOffset()
		} );

comment:2 Changed 6 years ago by Scott González

Owner: set to Scott González
Resolution: fixed
Status: newclosed

In 1d40952:

Sortable: Fix parent offset detection

Fixes #15021
Closes gh-1749

comment:3 Changed 6 years ago by Scott González

Milestone: none1.12.2
Note: See TracTickets for help on using tickets.