2018-05-10 01:56:02 +08:00
|
|
|
export class PageHelper {
|
|
|
|
private static readonly supportPageOffset = window.pageXOffset !== undefined;
|
2022-04-05 01:37:31 +08:00
|
|
|
private static readonly isCSS1Compat =
|
2023-09-12 00:57:51 +08:00
|
|
|
(document.compatMode || '') === 'CSS1Compat';
|
2018-05-17 06:52:08 +08:00
|
|
|
private static readonly body = document.getElementsByTagName('body')[0];
|
2018-05-10 01:56:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
public static get ScrollY(): number {
|
2022-04-05 01:37:31 +08:00
|
|
|
return this.supportPageOffset
|
2023-09-12 00:57:51 +08:00
|
|
|
? window.pageYOffset
|
|
|
|
: this.isCSS1Compat
|
|
|
|
? document.documentElement.scrollTop
|
|
|
|
: document.body.scrollTop;
|
2018-05-10 01:56:02 +08:00
|
|
|
}
|
|
|
|
|
2018-05-27 08:49:55 +08:00
|
|
|
public static set ScrollY(value: number) {
|
|
|
|
window.scrollTo(this.ScrollX, value);
|
|
|
|
}
|
|
|
|
|
2019-01-19 07:18:20 +08:00
|
|
|
public static get MaxScrollY(): number {
|
2022-04-05 01:37:31 +08:00
|
|
|
return (
|
2023-09-12 00:57:51 +08:00
|
|
|
Math.max(
|
|
|
|
document.body.scrollHeight,
|
|
|
|
document.body.offsetHeight,
|
|
|
|
document.documentElement.clientHeight,
|
|
|
|
document.documentElement.scrollHeight,
|
|
|
|
document.documentElement.offsetHeight
|
|
|
|
) - window.innerHeight
|
2022-04-05 01:37:31 +08:00
|
|
|
);
|
2019-01-19 07:18:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static get ScrollX(): number {
|
2022-04-05 01:37:31 +08:00
|
|
|
return this.supportPageOffset
|
2023-09-12 00:57:51 +08:00
|
|
|
? window.pageXOffset
|
|
|
|
: this.isCSS1Compat
|
|
|
|
? document.documentElement.scrollLeft
|
|
|
|
: document.body.scrollLeft;
|
2019-01-19 07:18:20 +08:00
|
|
|
}
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
public static showScrollY(): void {
|
2018-05-17 06:52:08 +08:00
|
|
|
PageHelper.body.style.overflowY = 'scroll';
|
2018-05-10 01:56:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static isScrollYVisible(): boolean {
|
2023-03-22 03:24:08 +08:00
|
|
|
return PageHelper.body.style.overflowY === 'scroll' ||
|
2023-09-12 00:57:51 +08:00
|
|
|
(!PageHelper.body.style.overflowY && document.documentElement.scrollHeight > document.documentElement.clientHeight);
|
2018-05-10 01:56:02 +08:00
|
|
|
}
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
public static hideScrollY(): void {
|
2018-05-17 06:52:08 +08:00
|
|
|
PageHelper.body.style.overflowY = 'hidden';
|
2018-05-10 01:56:02 +08:00
|
|
|
}
|
|
|
|
}
|