@morjs/runtime-web
Version:
mor runtime for web
39 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPosition = exports.looseBody = exports.fixedBody = void 0;
// 解决滚动穿透,紧固页面
const fixedBody = (document) => {
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
const style = `position: fixed; top: -${scrollTop}px; left: 0; right: 0;height: 100%;`;
document.body.style.cssText += style;
};
exports.fixedBody = fixedBody;
// 解决滚动穿透,释放页面
const looseBody = (document) => {
const body = document.body;
const top = body.style.top;
body.style.position = '';
document.body.scrollTop = document.documentElement.scrollTop =
-parseFloat(top);
body.style.top = body.style.left = body.style.right = body.style.bottom = '';
body.style.height = 'auto';
};
exports.looseBody = looseBody;
/**
* 设备是否支持触摸事件
*/
function supportTouch() {
return 'ontouchend' in document ? true : false;
}
// 获取当前点击位置
const getPosition = ({ changedTouches = [], x = 0, y = 0 }) => {
if (supportTouch()) {
const touch = changedTouches[0];
if (touch)
return { x: touch.clientX, y: touch.clientY };
return { x, y };
}
return { x, y };
};
exports.getPosition = getPosition;
//# sourceMappingURL=utils.js.map