2018-05-10 01:56:02 +08:00
|
|
|
export class PageHelper {
|
|
|
|
private static readonly supportPageOffset = window.pageXOffset !== undefined;
|
|
|
|
private static readonly isCSS1Compat = ((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
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static get ScrollY(): number {
|
|
|
|
return this.supportPageOffset ? window.pageYOffset : this.isCSS1Compat ? document.documentElement.scrollTop : document.body.scrollTop;
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
return Math.max(document.body.scrollHeight, document.body.offsetHeight,
|
|
|
|
document.documentElement.clientHeight, document.documentElement.scrollHeight,
|
|
|
|
document.documentElement.offsetHeight) - window.innerHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static get ScrollX(): number {
|
|
|
|
return this.supportPageOffset ? window.pageXOffset : this.isCSS1Compat ? document.documentElement.scrollLeft : document.body.scrollLeft;
|
|
|
|
}
|
|
|
|
|
2018-05-10 01:56:02 +08:00
|
|
|
public static showScrollY() {
|
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 {
|
2018-05-17 06:52:08 +08:00
|
|
|
return PageHelper.body.style.overflowY === 'scroll';
|
2018-05-10 01:56:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static hideScrollY() {
|
2018-05-17 06:52:08 +08:00
|
|
|
PageHelper.body.style.overflowY = 'hidden';
|
2018-05-10 01:56:02 +08:00
|
|
|
}
|
|
|
|
}
|