背景:使用angular8安裝的 Fuse-v8.0.0-demo 后台的框架
錨點: id='nearby'
流程:無論是點擊觸發方法也好,還是直接調用方法也好,這里只寫
引入:
import {Component, ViewEncapsulation, OnInit, OnDestroy, ElementRef, ViewChild, AfterViewInit} from '@angular/core';
import {FusePerfectScrollbarDirective} from '../../../../../@fuse/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive';
屬性:
@ViewChild(FusePerfectScrollbarDirective, {static: false})
directiveScroll: FusePerfectScrollbarDirective;
方法:
// 在頁面渲染完成時,開始執行這個方法
ngAfterViewInit(): void
{
setTimeout(() => {
this.scrollToBottom();
});
}
/**
* Scroll to the bottom
* speed是頁面滾動的速度
* @param {number} speed
*/
scrollToBottom(speed?: number): void
{
speed = speed || 400;
if ( this.directiveScroll )
{
// this.directiveScroll.update();
setTimeout(() => {
this.directiveScroll.scrollToElement('#nearday' , 0 , speed); //頁面滾動到nearday的地方
});
}
}
頁面渲染部分:
在html頁面中滾動的那個div加上 放上屬性
fusePerfectScrollbar
如
<div 這里外層的div要overflow:hidden>
<div fusePerfectScrollbar 這里是滾動的部分>
<section>這里是內容</section>
</div>
</div>