有没有办法在单击按钮时以角度滚动到页面底部?

w.b*_*ham 3 html css jquery typescript angular

我正在开发一个有角度的项目,我需要找到一种方法,当用户单击按钮时自动滚动到页面底部。

我尝试使用 jQuery 函数 animate() 执行此操作,但这对我不起作用。我也尝试过以下功能:

scrollToBottom() {
  let myElement = document.getElementById("myPageId");
  myElement.scrollTop = myElement.scrollHeight;
}
Run Code Online (Sandbox Code Playgroud)

该函数仅在我从 html 页面调用它时才有效,而当用户单击按钮时我需要在 ts 文件中使用它。

Akb*_*bal 5

创建一个按钮来执行由 @chestas 编写的普通 JavaScript,也可以在此处使用

相关TS

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular';
  goToBottom(){
    window.scrollTo(0,document.body.scrollHeight);
  }
}
Run Code Online (Sandbox Code Playgroud)

相关HTML

<button type="button" (click)="goToBottom()">go to bottom </button>
Run Code Online (Sandbox Code Playgroud)

完整的堆栈闪电战