簡體   English   中英

如何在點擊 angular 時滾動到底部

[英]How to scroll to bottom on click in angular

我想在點擊時滾動到底部,我嘗試使用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>

你可以這樣做:

showService() {
  let position = document.getElementById("serviceBox").getBoundingClientRect().top + window.scrollY - 25;
  window.scrollTo({ top: position, behavior: 'smooth' });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM