[英]How to ScrollDown nested scroll bar to the bottom of the nested scroll div on button click in 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.