以下是一个使用Angular的示例代码,用于滚动到元素底部:
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponent {
@ViewChild('scrollToBottomElement', { static: false }) scrollToBottomElement: ElementRef;
scrollDown() {
this.scrollToBottomElement.nativeElement.scrollIntoView({ behavior: 'smooth' });
}
}
这样,当点击按钮时,页面会平滑滚动到指定的元素底部。