htmlcssangulartypescriptscroll

How do I auto scroll in Angular?


I got a dynamic component, where I add material cards horizontally. After a few cards, the component gets filled, and I can scroll the component. But how can I make it auto scroll horizontally, so that I don't have to use the mouse all the time?

I already tried playing with some css attributes like overflow and so on.

.blocksWrapper {
  display: flex;
  overflow: auto;
  min-height: 305px;
}

I expect, that it autoscrolls horizontally.

This is how it should look like:

enter image description here

But instead it never scrolls automatically.


Solution

  • There is no automatic feature to auto scroll a div when the size changes.
    I suppose you dynamically add your cards using some button? Then you could scroll programatically when adding a card!

    Here are multiple suggested solutions:

    Here is an example using the solution 2) : https://angular-dfjmej.stackblitz.io

    Maybe it's not the exact render you want, but it's only a matter of settings then.