But you have to figure out the height of the elements by yourself to calculate the y position to scoll to. Unfortunately as far as I know there is no method yet for getting the current scroll position to be able to scroll relatively. Thus you have to calculate the absolute position. Hope this helps!
I have been binding id properties of JSON obects that I am dynamically displaying via *ngFor to their respective HTML element ids, e.g:
<p *ngFor="let jsonObj of myObjects" [id]="jsonObj.id">
In my page component, I have a method that takes the same id as an argument and gets the offsetTop property of the dom element with this id, which I then use as the y value to scroll to:
scrollTo(element:string) {
let yOffset = document.getElementById(element).offsetTop;
this.content.scrollTo(0, yOffset, 4000)
}
Currently, this does a nice scroll to the element, although I’m not sure how reliable the offsetTop property will be with more complex layouts. For your need, I think you would first call content.resize() to update the layout, and then use the element id of the target accordion element to get the offsetTop value to scroll to. All pure conjecture of course.
I’m having trouble using this
do you literally have element: string and this.content in your code or do those stand for other variables specific to the project?
Also, why is scrollTo within itself?
Apologies if this is a dumb question, I am not well versed in coding jargon .
I arbitrarily named the method scrollTo() in my page component. You could name this whatever you want. My scrollTo() method is defined on the page component; the ion-content scrollTo() method is part of the ionic API. (perhaps confusingly) named the same, but they are two different methods on two separate components. hth.