dora-ui
Version:
A React.js Mobile UI Library
28 lines (23 loc) • 678 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.stopBodyScroll = void 0;
var stopBodyScroll = function () {
var top = 0;
return function () {
var isFixed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var bodyEl = document.body;
if (isFixed) {
top = window.scrollY;
bodyEl.style.position = 'fixed';
bodyEl.style.top = -top + 'px'; // 居中样式
bodyEl.style.left = '0px';
bodyEl.style.right = '0px';
} else {
bodyEl.style.position = '';
window.scrollTo(0, top); // 回到原先的top
}
};
}();
exports.stopBodyScroll = stopBodyScroll;