mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 19:19:26 +08:00
18 lines
469 B
TypeScript
18 lines
469 B
TypeScript
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') {
|
|
ret = window.document.documentElement[method];
|
|
}
|
|
|
|
return ret;
|
|
}
|