How do I make a css scroll bar in microsoft edge go back to top when changing pages?

Asked

Viewed 69 times

1

  • Error in: Microsoft Edge

  • Technology used: Angular(4+)

  • When it happens: Only when the screen size is small, and not it is possible to display all items of the table listing
  • Table Used: Angular Material

Next, I’m doing a project with Angular(4+), where I’m using a Material Angular table.

Our scrollbar is activated when the screen is small, and when the user clicks on next items, the edge renders the next items, using the scroll set down

At first glance, the edge displays the table normally with the scroll bar and the items. When the user clicks to see the next results, since we display 10 at a time, the edge renders with the scroll down, forcing the user to have to scroll up the screen again.

inserir a descrição da imagem aqui

Scroll is created through the following css class:

  .table-container {
    flex: 1;
    overflow: auto;   
    display: flex;
    flex-direction: column;
  }

Code I used to solve:

  /** 
   * This function fix report scroll position after change page listener 
   */ 
  materialScrollDownToUp() { 
    document.getElementById('material-scroll-detect').scrollTop = 0; 
  } 

Then you just make use of that call where you need to, and it doesn’t get in a loop, hugs.

  • It’s just Edge that happens?

  • @dvd yes, it’s only in microsoft edge that this happens

  • @DVD Beauty, I’ll try here

  • @dvd worked well brother, the bid was the place where set the ID bag ? I was setting in the father div, but the right place was to be put there <mat-table> </mat-table>, what a wave, but it was worth partner by the cleared there

1 answer

2


Move the element scroll to the top using scrollTop = 0 with a little delay in the setTimeout:

setTimeout(function(){
    document.querySelector(seletor).scrollTop = 0;
}, 50);

Where has seletor you place an id, class, tag or that is necessary to select the element in which you want to apply the scroll.

  • This way tbem works, only I did it the following way @dvd. I put the scrollTop in a function, in which case I do not enter a loop and be quiet, check: /** * This Function fix report scroll position after change page Listener */ materialScrollDownToUp() { Document.getElementById('material-scroll-Detect'). scrollTop = 0; }

  • I got it. it’s cool too

Browser other questions tagged

You are not signed in. Login or sign up in order to post.