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