Ionic 3 ion-list: how to know item's position to scrollto?


#1

Hi,

Inside ion-list I have this

<ion-item [id]="item.itemId">

Each item has a date and the list is sorted down, by this date. When the view is loaded, I want the list to scroll automatically so the next item (chronologically) after today, will be the first visible one.

I have this code

scrollToNextOne(element:string) {
    let yOffset = document.getElementById(element).offsetTop;
    this.content.scrollTo(0, yOffset, 2000);
  }

But I don’t know the element id to scroll to. How can I know which item is the one that I need?

Thanks


#2

See: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView