“Posisi Gulir” Kode Jawaban

JavaScript mendapatkan posisi gulir

function getYPosition(){
  var top  = window.pageYOffset || document.documentElement.scrollTop
  return top;
}
Phil the ice cream man

Log Window Scrollpostion

$(window).on('scroll', function() {
    console.log( $(this).scrollTop() );
});
Panicky Pig

Gulir, posisi

      
      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
}
    
Agreeable Addax

Gulir, posisi

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 { }
}
Agreeable Addax

Posisi Gulir

$(window).scroll(function() {
	var $height = $(window).scrollTop();
  if($height > 50) {
		//do something
	} else {
		//do something
	}
});
Malario

Jawaban yang mirip dengan “Posisi Gulir”

Pertanyaan yang mirip dengan “Posisi Gulir”

Lebih banyak jawaban terkait untuk “Posisi Gulir” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya