jasonslyvia / react-anything-sortable

A ReactJS component that can sort any children with touch support and IE8 compatibility
http://jasonslyvia.github.io/react-anything-sortable/demo/
MIT License
460 stars 84 forks source link

Get container position on mouse down #87

Open yuzexing opened 7 years ago

yuzexing commented 7 years ago

There is problem when get contianer position at componentDidUpdate:

When container scroll out of visual range then update position, scroll back, we can't call handleMouseMove correctly

Why not let it work onMouseDown.

 `handleMouseDown: function handleMouseDown(e, index) {
    this._draggingIndex = index;
    this._prevX = e.pageX || e.clientX;
    this._prevY = e.pageY || e.clientY;
    this._initOffset = e.offset;
    this._isReadyForDragging = true;
    this._hasInitDragging = false;

    var container = _reactDom2['default'].findDOMNode(this);
    var rect = container.getBoundingClientRect();

    var scrollTop = doc.docElement && doc.docElement.scrollTop || doc.body.scrollTop;
    var 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;

    // start listening mousemove and mouseup
    this.bindEvent();
  }`
jasonslyvia commented 7 years ago

Do you care making a PR upon this change? I will sure be interested to review it!