它应该很简单,但从昨天开始,我试图在页面上平滑向上滚动。滚动功能有效,但不能平滑滚动。
我试过 : scrollIntoView({behavior: 'smooth'}),但它不起作用。
这是我的 html 组件
<div *ngIf="displayNoneOnBtn" [hidden]="!displayNoneOnBtn" id="btnTest" class="shadow d-flex flex-column align-items-center justify-content-center">
<ng-container *ngIf="!disableBtn">
<i class="material-icons arrow-up-button" (click)="scrollTopWindow()">keyboard_arrow_up</i>
</ng-container>
<ng-container *ngIf="disableBtn">
<i class="material-icons arrow-down-button" (click)="scrollDown()">keyboard_arrow_down</i>
</ng-container>
</div>
Run Code Online (Sandbox Code Playgroud)
还有我的 TS 组件
import {Component, OnInit, ElementRef} from '@angular/core';
import 'hammerjs';
import { SessionService, UiService } from 'src/app/core/services';
@Component({
templateUrl: './frontend.component.html',
styleUrls: ['./frontend.component.scss'],
})
export class FrontendComponent implements OnInit {
top: number;
disableBtn = true;
scrollHeight: number;
displayNoneOnBtn = true;
constructor(
public sessionService: SessionService,
public uiService: UiService, …Run Code Online (Sandbox Code Playgroud)