Struggling with a scroll function to maintain position while scrolling up or down - encountering an error:
Error: Type 'HTMLDivElement | null' is not assignable to type 'HTMLDivElement'.
Type 'null' is not assignable to type 'HTMLDivElement'.ts(2322)
If anyone can assist in fixing this issue, it would be greatly appreciated!
scrollFunction = (): void => {
if (this.isLargerScreenMedia()) {
// some code here
} else {
const scrollPosition: number = document.documentElement.scrollTop;
const container: HTMLDivElement =
this.tripTotalContainer.querySelector('.trip-total-module');
if (container) {
if (scrollPosition > this.lastScrollPosition) {
//scrolling down
container.style.bottom = '0px';
} else {
//scrolling up
container.style.bottom = '27px';
}
}
this.lastScrollPosition = scrollPosition < 0 ? 0 : scrollPosition;
this.tripTotalContainer.classList.add('sticky-bottom');
}
};