ngx-dnd icon indicating copy to clipboard operation
ngx-dnd copied to clipboard

scroll when dragging

Open KumailHussain opened this issue 6 years ago • 12 comments

If i have a large number of items the container can't scroll at own

KumailHussain avatar Aug 15 '18 06:08 KumailHussain

Anyone have suggestions on how to do this? This would be very beneficial to me as well

MNorgren avatar Sep 28 '18 19:09 MNorgren

Set a timer function when dragging, check if the dragged item is outside the container, and scroll the container.

jarhys avatar Oct 01 '18 10:10 jarhys

You can try https://github.com/hollowdoor/dom_autoscroller Worked for me for this exact issue.

jzahka avatar Oct 15 '18 14:10 jzahka

@jzahka Can you please provide a code example? Or did it just work out of the box?

Supamiu avatar Oct 26 '18 13:10 Supamiu

I more or less copied the example in the repo https://github.com/hollowdoor/dom_autoscroller#usage

import autoScroll from 'dom-autoscroller';
// ...

constructor(private element: ElementRef) {}
// ...
ngAfterViewInit() {
  autoScroll([
    this.element.nativeElement // element needs to be scrollable
  ], {
    margin: 50,
    maxSpeed: 20,
    autoScroll: function() {
      // only scroll when mouse is down
      // `this` does not refer to component here
      return this.down;
    }
  });
}

jzahka avatar Oct 26 '18 13:10 jzahka

Do you have performance problems at home with ngx-dnd and dom_autoscroll? I made a kind of board like Trello (much lighter in terms of features), I added dom_autoscroll to scroll vertically and horizontally but the interface is very jerky. Do you have the same problem?

GitHubish avatar Feb 22 '19 15:02 GitHubish

@GitHubish I haven't had the jerky interface issue you describe.

jzahka avatar Feb 22 '19 15:02 jzahka

I did a test project, the problem arises as soon as there are a certain number of elements displayed. In my case with an interface without CSS, without any other complexity / heaviness caused by other components, animations jerk with 250 elements.

GitHubish avatar Feb 25 '19 15:02 GitHubish

@jzahka how do you destroy when leaving the component?

hijoncon avatar Mar 28 '19 21:03 hijoncon

@jzahka @GitHubish You should initialize autoScroll inside runOutsideAngular for better performance so all events catched up by listeners registered in autoScroll will not cause change detection to run

marcio199226 avatar Jul 04 '19 07:07 marcio199226

Hey @hijoncon Did you find a solution or work around on how to destroy when leaving the component!?

Kartheek2016 avatar Jul 24 '20 14:07 Kartheek2016

I believe you can use destroy() on the instance returned by the autoScroll() function. https://github.com/hollowdoor/dom_autoscroller#destroyforcecleananimation

jzahka avatar Jul 24 '20 14:07 jzahka