overscroll
Version:
54 lines (42 loc) • 1.4 kB
JavaScript
import { get } from '../css';
import { hasData } from './domData';
// 实际情况下 body documentElement 不会都设置 overflow: scroll
// 推荐 html, body { height: 100% } body { overflow: auto; }
function compose(funcA, funcB) {
return function () {
return funcA(funcB.apply(undefined, arguments));
};
}
var scrollable = function scrollable(attr) {
return function (dom) {
return ['overlay', 'scroll', 'auto'].includes(get(dom, attr));
};
};
export default (function (_ref) {
var body = _ref.body,
html = _ref.html,
target = _ref.target,
OVERSCROLLX = _ref.OVERSCROLLX,
OVERSCROLLY = _ref.OVERSCROLLY;
function hasScrollX(dom) {
return dom.scrollWidth > dom.clientWidth && (hasData(dom, OVERSCROLLX) || scrollable('overflow-x')(dom));
}
function hasScrollY(dom) {
return dom.scrollHeight > dom.clientHeight && (hasData(dom, OVERSCROLLY) || scrollable('overflow-y')(dom));
}
function scrollingElement() {
var dom = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : target;
return dom === body ? html : dom;
}
function hasScroll(dom) {
return {
x: hasScrollX(dom),
y: hasScrollY(dom)
};
}
return {
hasScroll: compose(hasScroll, scrollingElement),
hasScrollX: compose(hasScrollX, scrollingElement),
hasScrollY: compose(hasScrollY, scrollingElement)
};
});