1function getYPosition(){
2 var top = window.pageYOffset || document.documentElement.scrollTop
3 return top;
4}
1$(window).on('scroll', function() {
2 console.log( $(this).scrollTop() );
3});
1$(window).scroll(function() {
2 var $height = $(window).scrollTop();
3 if($height > 50) {
4 //do something
5 } else {
6 //do something
7 }
8});
1
2 abstract class ViewportScroller {
3 abstract setOffset(offset: [number, number] | (() => [number, number])): void
4 abstract getScrollPosition(): [number, number]
5 abstract scrollToPosition(position: [number, number]): void
6 abstract scrollToAnchor(anchor: string): void
7 abstract setHistoryScrollRestoration(scrollRestoration: "auto" | "manual"): void
8}
9
1import { HostListener } from '@angular/core';
2
3@ViewChild('curtain') divCurtain: ElementRef;
4
5export class ComponentX {
6 @HostListener('window:scroll', ['$event']) onScrollEvent($event) {
7 console.log(window.pageYOffset);
8 this.divCurtain.nativeElement.style.top = window.pageYOffset.toString().concat('px');
9 }
10
11 ngOnInit(): void { }
12}
13