I have to check if a div(scrollApplist) has scrollbar enabled. If scrollbar is visible, small margin will be applied. If scrollbar is not visible, large margin will be applied(Scrollbar height is added dynamically)
<div id="scrollApplist" [ngStyle]="{ height: scrollBarHeight }" class="cardlistScrollBar">
<div [ngClass]="this.isScrollBarVisible?'smallMarginRight':'largeMarginRight'">
<card-list [cardItems]="records"></card-list>
</div>
</div>
.cardlistScrollBar{
overflow-y: auto;
border-radius: 4px;
line-height: normal;
}
As per this document How can I check if a scrollbar is visible?, I checked scrollHeight and clientHeight of this div scrollApplist.
function scrollbarVisible(element) {
return element.scrollHeight > element.clientHeight;
}
Using this condition :
document.querySelector('#scrollApplist').scrollHeight > document.querySelector('#scrollApplist').clientHeight
But scrollHeight and clientHeight are same on the first load(When first time rendering the application) even if scrollbar is visible. All other cases, it is working fine. How to resolve this issue?