dora-ui
Version:
A React.js Mobile UI Library
19 lines (17 loc) • 529 B
JavaScript
export 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
}
};
}();