How to Scroll to top of a list?

Hi All,

I am using Ionic2.

I have a list of items. On an event (messageSend function called), I would like to scroll to the top of the list.


<ion-content padding class="messages-page-content">
	<ion-scroll scrollY="true" class="messages">
  <ion-list class="message-list">
    <ion-item ....


messageSend(va, vi) {
  // scroll to top of list

Any advise appreciated.

with ion-scroll I would do

 @ViewChild('yourScroll') scrollY: Scroll;

 this.scrollY.scrollElement.scrollTop = 0;

Thanks, just a quick question, what is 'yourScroll'? Where should that be defined?

ps. Also can you scroll to the bottom rather?

 <ion-scroll #yourScroll scrollY="true" class="messages">
1 Like

Thank you

Looking at scrollElement, is it possible to rather scroll to the bottom?

to scroll to the bottom then I guess you have to play with the scrollElement, there is probably a property which give you the current height, just assign then the scrollBottom to that height

1 Like

side note, what you could also do, if it is possible in your case, is to get rid of using an ion-scroll and just scrollToBottom() of the content

1 Like