ant-design/components/_util/getScroll.tsx

18 lines
470 B
TypeScript
Raw Normal View History

2017-11-22 11:34:46 +08:00
export default function getScroll(target: any, 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[prop] : target[method];
// ie6,7,8 standard mode
if (isWindow && typeof ret !== 'number') {
2018-09-30 16:07:01 +08:00
ret = window.document.documentElement![method];
}
return ret;
}