Set scroll position to top of page (when changing displayed div)

#1

On my single-page app when I change from a div to another div (with different contents) using ngSwitch, the scroll position stays the same - so when the new div appears, the position is not at the top.

I would think there must be a simple solution I just don’t know of, but anyway here is what I tried so far:

  1. scrollToTop() (using @ViewChild(Content) ): OK, this does make the page scroll to the top, but it just slowly crawls up, and that’s not that great. What I want is simply to start at the top, so set the scroll position to top instantly. I could not find how I might modify the speed for this function.

  2. scroll(0, 0); or scrollTo(0, 0); and so on in pure JS: they just don’t work in ionic it seems.

  3. I tried inserting a dummy div with no content and changing first to that before the actual one I want to display, to trick the scroll position into a zero position, but still it does not work, scroll stays where it was set in the original div.

#2

Actually the answer is very simple, scrollToTop() has scrollToTop(_duration_) to set timing, I must have just missed it in the documentation… So it will be scrollToTop(0)
(https://ionicframework.com/docs/api/components/content/Content/)