Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,7 @@ const Sortable = createReactClass({
},

componentDidUpdate() {
const container = ReactDOM.findDOMNode(this);
const rect = container.getBoundingClientRect();

const scrollTop = (doc.docElement && doc.docElement.scrollTop) || doc.body.scrollTop;
const scrollLeft = (doc.docElement && doc.docElement.scrollLeft) || doc.body.scrollLeft;

this._top = rect.top + scrollTop;
this._left = rect.left + scrollLeft;
this._bottom = this._top + rect.height;
this._right = this._left + rect.width;
this.calculateContainer();
},

componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -170,6 +161,8 @@ const Sortable = createReactClass({
this._isReadyForDragging = true;
this._hasInitDragging = false;

// calculate container current position
this.calculateContainer();
// start listening mousemove and mouseup
this.bindEvent();
},
Expand Down Expand Up @@ -334,6 +327,20 @@ const Sortable = createReactClass({
return arr;
},

calculateContainer() {
const container = ReactDOM.findDOMNode(this);
if (!container) return;
const rect = container.getBoundingClientRect();

const scrollTop = (doc.docElement && doc.docElement.scrollTop) || doc.body.scrollTop;
const scrollLeft = (doc.docElement && doc.docElement.scrollLeft) || doc.body.scrollLeft;

this._top = rect.top + scrollTop;
this._left = rect.left + scrollLeft;
this._bottom = this._top + rect.height;
this._right = this._left + rect.width;
},

/**
* calculate new offset
* @param {object} e MouseMove event
Expand Down