1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00
pigallery2/src/frontend/app/model/page.helper.ts

52 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-05-09 13:56:02 -04:00
export class PageHelper {
private static readonly supportPageOffset = window.pageXOffset !== undefined;
2022-04-04 19:37:31 +02:00
private static readonly isCSS1Compat =
(document.compatMode || '') === 'CSS1Compat';
2018-05-16 18:52:08 -04:00
private static readonly body = document.getElementsByTagName('body')[0];
2018-05-09 13:56:02 -04:00
public static get ScrollY(): number {
2022-04-04 19:37:31 +02:00
return this.supportPageOffset
? window.pageYOffset
: this.isCSS1Compat
? document.documentElement.scrollTop
: document.body.scrollTop;
2018-05-09 13:56:02 -04:00
}
public static set ScrollY(value: number) {
window.scrollTo(this.ScrollX, value);
}
2019-01-19 00:18:20 +01:00
public static get MaxScrollY(): number {
2022-04-04 19:37:31 +02:00
return (
Math.max(
document.body.scrollHeight,
document.body.offsetHeight,
document.documentElement.clientHeight,
document.documentElement.scrollHeight,
document.documentElement.offsetHeight
) - window.innerHeight
);
2019-01-19 00:18:20 +01:00
}
public static get ScrollX(): number {
2022-04-04 19:37:31 +02:00
return this.supportPageOffset
? window.pageXOffset
: this.isCSS1Compat
? document.documentElement.scrollLeft
: document.body.scrollLeft;
2019-01-19 00:18:20 +01:00
}
public static showScrollY(): void {
2018-05-16 18:52:08 -04:00
PageHelper.body.style.overflowY = 'scroll';
2018-05-09 13:56:02 -04:00
}
public static isScrollYVisible(): boolean {
2018-05-16 18:52:08 -04:00
return PageHelper.body.style.overflowY === 'scroll';
2018-05-09 13:56:02 -04:00
}
public static hideScrollY(): void {
2018-05-16 18:52:08 -04:00
PageHelper.body.style.overflowY = 'hidden';
2018-05-09 13:56:02 -04:00
}
}