Skip to content

Commit 5f09738

Browse files
MKirovaMayaKirova
authored andcommitted
chore(*): Recalc virtual height before use.
1 parent 40ff730 commit 5f09738

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,8 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
731731
if (!parseInt(this.scrollComponent.nativeElement.style.height, 10)) {
732732
return;
733733
}
734-
735-
const containerSize = parseInt(this.igxForContainerSize, 10);
736-
const maxRealScrollTop = event.target.children[0].scrollHeight - containerSize;
737-
const realPercentScrolled = maxRealScrollTop !== 0 ? event.target.scrollTop / maxRealScrollTop : 0;
738734
if (!this._bScrollInternal) {
739-
const maxVirtScrollTop = this._virtHeight - containerSize;
740-
this._virtScrollTop = realPercentScrolled * maxVirtScrollTop;
735+
this._calcVirtualHeight(event.target.scrollTop);
741736
} else {
742737
this._bScrollInternal = false;
743738
}
@@ -1306,11 +1301,21 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
13061301
}
13071302
private _updateVScrollOffset() {
13081303
let scrollOffset = 0;
1304+
this._calcVirtualHeight(this.scrollPosition);
13091305
const vScroll = this.scrollComponent.nativeElement;
13101306
scrollOffset = vScroll && this.scrollComponent.size ?
13111307
this._virtScrollTop - this.sizesCache[this.state.startIndex] : 0;
13121308
this.dc.instance._viewContainer.element.nativeElement.style.top = -(scrollOffset) + 'px';
13131309
}
1310+
1311+
protected _calcVirtualHeight(scrollTop: number) {
1312+
const containerSize = parseInt(this.igxForContainerSize, 10);
1313+
const maxRealScrollTop = this.scrollComponent.size - containerSize;
1314+
const realPercentScrolled = maxRealScrollTop !== 0 ? scrollTop / maxRealScrollTop : 0;
1315+
const maxVirtScrollTop = this._virtHeight - containerSize;
1316+
this._virtScrollTop = realPercentScrolled * maxVirtScrollTop;
1317+
}
1318+
13141319
private _updateHScrollOffset() {
13151320
let scrollOffset = 0;
13161321
scrollOffset = this.scrollComponent.nativeElement &&
@@ -1581,13 +1586,8 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
15811586
if (!parseInt(this.scrollComponent.nativeElement.style.height, 10)) {
15821587
return;
15831588
}
1584-
1585-
const containerSize = parseInt(this.igxForContainerSize, 10);
1586-
const maxRealScrollTop = event.target.children[0].scrollHeight - containerSize;
1587-
const realPercentScrolled = maxRealScrollTop !== 0 ? event.target.scrollTop / maxRealScrollTop : 0;
15881589
if (!this._bScrollInternal) {
1589-
const maxVirtScrollTop = this._virtHeight - containerSize;
1590-
this._virtScrollTop = realPercentScrolled * maxVirtScrollTop;
1590+
this._calcVirtualHeight(event.target.scrollTop);
15911591
} else {
15921592
this._bScrollInternal = false;
15931593
}

0 commit comments

Comments
 (0)