Scroll Automatically to the Bottom of the Page

后端 未结 24 2888
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 05:22

Consider I have a list of questions. When I click on the first question, it should automatically take me to the bottom of the page.

For a matter of fact, I do know

24条回答
  •  日久生厌
    2020-11-22 05:56

    I've had the same issue. For me at one point in time the div's elements were not loaded entirely and the scrollTop property was initialized with the current value of scrollHeight, which was not the correct end value of scrollHeight.

    My project is in Angular 8 and what I did was:

    1. I used viewchild in order to obtain the element in my .ts file.
    2. I've inherited the AfterViewChecked event and placed one line of code in there which states that the viewchild element has to take into the scrollTop value the value of scrollHeight (this.viewChildElement.nativeElement.scrollTop = this.viewChildElement.nativeElement.scrollHeight;)

    The AfterViewChecked event fires a few times and it gets in the end the proper value from scrollHeight.

提交回复
热议问题