mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 04:48:02 +08:00
18 lines
532 B
TypeScript
18 lines
532 B
TypeScript
export default function getScroll(target: HTMLElement | Window | null, top: boolean): number {
|
|
if (typeof window === 'undefined') {
|
|
return 0;
|
|
}
|
|
|
|
const prop = top ? 'pageYOffset' : 'pageXOffset';
|
|
const method = top ? 'scrollTop' : 'scrollLeft';
|
|
const isWindow = target === window;
|
|
|
|
let ret = isWindow ? (target as Window)[prop] : (target as HTMLElement)[method];
|
|
// ie6,7,8 standard mode
|
|
if (isWindow && typeof ret !== 'number') {
|
|
ret = (document.documentElement as HTMLElement)[method];
|
|
}
|
|
|
|
return ret;
|
|
}
|