I have tried almost every solution that is available online but nothing worked out, below are few solutions I tried
My actual scenario is to show a specific div element when the other div element goes off from the screen when the screen is scrolled down.
I'm able to do this on desktops/laptops but not on mobiles where the scroll event doesn't fire at all.
my Desktop / Laptop scroll event listener I'm using is
@HostListener('window:scroll', ['$event']) getScrollHeight(event) {
console.log('from desk' , window.pageYOffset, event);
}
While for the mobile as my scroll event doesn't fire so I used below
@HostListener('window:touchStart', ['$event']) checkTouchEnd(event) {
this.start = event.changedTouches[0];
});
@HostListener('window:touchend', ['$event']) checkTouchEnd(event) {
this.end = event.changedTouches[0];
let scrollpositionValue;
if((this.end.screenY - this.start.screenY) > 0) {
console.log('scrolling up');
console.log('[scroll-up]', this.end.screenY - this.start.screenY);
scrollpositionValue = this.end.screenY - this.start.screenY;
} else if(this.end.screenY - this.start.screenY < 0) {
console.log('scrolling down');
console.log('[scroll-down]', this.end.screenY - this.start.screenY);
scrollpositionValue = this.end.screenY - this.start.screenY;
}
const scrollPosition = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
console.log('[scroll]', scrollPosition);
});
Can somebody help me with a solution, All I want is to get the scrollY position on a mobile browser scrolled.
thanks in advance!