ant-design-vue/components/_util/getScroll.ts

18 lines
447 B
TypeScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
export default function getScroll(target, top) {
2017-12-07 10:33:33 +00:00
if (typeof window === 'undefined') {
2019-01-12 03:33:27 +00:00
return 0;
2017-12-07 10:33:33 +00:00
}
2019-01-12 03:33:27 +00:00
const prop = top ? 'pageYOffset' : 'pageXOffset';
const method = top ? 'scrollTop' : 'scrollLeft';
const isWindow = target === window;
2017-12-07 10:33:33 +00:00
2019-01-12 03:33:27 +00:00
let ret = isWindow ? target[prop] : target[method];
2017-12-07 10:33:33 +00:00
// ie6,7,8 standard mode
if (isWindow && typeof ret !== 'number') {
2019-01-12 03:33:27 +00:00
ret = window.document.documentElement[method];
2017-12-07 10:33:33 +00:00
}
2019-01-12 03:33:27 +00:00
return ret;
2017-12-07 10:33:33 +00:00
}