为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 angular 中调用 ngx-perfect-scrollbar update()

如何在 angular 中调用 ngx-perfect-scrollbar update()

四季花海 2021-08-20 19:34:13
我使用"ngx-perfect-scrollbar": "^5.3.5"。我将描述添加为“查看更多”和“查看更少”,并且页面上有滚动。当执行“查看更多”和“查看更少”点击操作时,完美的滚动条不会自我更新,底部还有一个额外的空白。.html<div class="col-12 ps" [perfectScrollbar]="scrollConfig"><div class="seeMoreContent" *ngIf="seeMore === true">----------</div><div class="seeLessContent" *ngIf="seeMore === false">----------</div> <span (click)="updateSeeMore('seeMore')" class="seeMore">See more</span><span (click)="updateSeeMore('seeLess')" class="seeLess">  See Less</span></div>.tsscrollConfig = {    suppressScrollX: false,    suppressScrollY: false};updateSeeMore(type){if(type === 'seemore'){ this.seeMore = true;}else{ this.seeMore = false;}// Want to update the scroll here}   
查看完整描述

2 回答

?
红颜莎娜

TA贡献1842条经验 获得超12个赞

你可以这样使用


<perfect-scrollbar

                #perfectScroll

                [config]="psConfig"

                [scrollIndicators]="true"

                (psScrollY)="onListScroll()">

</perfect-scrollbar>

内部组件文件


import { PerfectScrollbarConfigInterface, PerfectScrollbarComponent } from 'ngx-perfect-scrollbar';


@ViewChild('perfectScroll') perfectScroll: PerfectScrollbarComponent;

现在你可以在你想要更新滚动的方法中使用它


this.perfectScroll.directiveRef.update(); //for update scroll

this.perfectScroll.directiveRef.scrollToTop(offset?, speed?); //for update scroll


查看完整回答
反对 回复 2021-08-20
?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

尝试对您的组件使用以下方式:

import { PerfectScrollbarDirective } from 'ngx-perfect-scrollbar';
@ViewChild(PerfectScrollbarDirective, { static: false }) perfectScrollbarDirectiveRef?: PerfectScrollbarDirective;
this.perfectScrollbarDirectiveRef.update();
this.perfectScrollbarDirectiveRef.scrollToTop(0, 1);



查看完整回答
反对 回复 2021-08-20
  • 2 回答
  • 0 关注
  • 320 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信