拖放自动滚动(dom-autoscrolling)

don*_*don 5 rxjs ng2-dragula

我有一个text元素列表,希望在拖动新元素时自动将列表滚动到底部。

一旦我拖放列表中的元素一次,下面的示例就可以正常工作。

我相信我需要observable在拖动之前调用一次。

我正在使用draguladom-autoscrolling

import {takeUntil} from "rxjs/internal/operators/takeUntil";
import * as autoScroll from 'dom-autoscroller';

const drake = this.dragulaService.find(this.dragulaBagName);
this.dragulaService.drag.pipe(
  takeUntil(this.destroyed$),
).subscribe(([bag, movingEl, containerEl]) => {
  autoScroll(containerEl.parentNode, {
    margin: 20,
    pixels: 10,
    scrollWhenOutside: true,
    autoScroll: function () {
      return this.down && drake && drake.drake && drake.drake.dragging;
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

显然,this.down在回调中autoScroll中设置为false......一旦拖放一次,它就可以正常工作。

有任何想法吗?

小智 3

尝试使用 (mousedown)="initAutoScroll()"

initAutoScroll(){
  const drake = this.dragulaService.find(this.dragulaBagName);
  this.scroll = autoScroll(
  containerEl.parentNode,
  {
    margin: 30,
    maxSpeed: 25,
    scrollWhenOutside: true,

    autoScroll: function () { 
      return this.down && drake.drake.dragging;
    }
  });
}


this.dragulaService.dragend.asObservable().subscribe(value => {
  if (this.scroll) {
    this.scroll.destroy();  // destroy when don't use auto-scroll
  }
});
Run Code Online (Sandbox Code Playgroud)