JavaScript Obtenha posição de rolagem
function getYPosition(){
var top = window.pageYOffset || document.documentElement.scrollTop
return top;
}
Phil the ice cream man
function getYPosition(){
var top = window.pageYOffset || document.documentElement.scrollTop
return top;
}
$(window).on('scroll', function() {
console.log( $(this).scrollTop() );
});
abstract class ViewportScroller {
abstract setOffset(offset: [number, number] | (() => [number, number])): void
abstract getScrollPosition(): [number, number]
abstract scrollToPosition(position: [number, number]): void
abstract scrollToAnchor(anchor: string): void
abstract setHistoryScrollRestoration(scrollRestoration: "auto" | "manual"): void
}
import { HostListener } from '@angular/core';
@ViewChild('curtain') divCurtain: ElementRef;
export class ComponentX {
@HostListener('window:scroll', ['$event']) onScrollEvent($event) {
console.log(window.pageYOffset);
this.divCurtain.nativeElement.style.top = window.pageYOffset.toString().concat('px');
}
ngOnInit(): void { }
}
$(window).scroll(function() {
var $height = $(window).scrollTop();
if($height > 50) {
//do something
} else {
//do something
}
});