【发布时间】:2022-01-04 12:34:29
【问题描述】:
我想在点击时滚动到底部,我尝试使用scrollIntoView,它滚动到页面的一半而不是div的部分
.ts 文件
@ViewChild("serviceBox", {static: false}) private serviceBox: ElementRef;
showService() {
setTimeout(() => {
this.serviceBox.nativeElement.scrollIntoView({behavior: 'smooth'})
});
}
.HTML
<div class="row" [style.display]="commonService.showService ? 'block' : 'none'">
<div class="col-md-12">
<div class="ticket__box" #serviceBox>
<app-service-details [contractId]="contractId" [contactId]="contactId" [memberID]="memberID" [serviceId]="commonService.serviceId"></app-service-details>
</div>
</div>
</div>
【问题讨论】:
-
您想滚动到页面底部,还是滚动到
#serviceBoxdiv? -
到#serviceBox div
-
我发布了答案。可以试试吗?
标签: javascript html angular typescript