@jusfoun-vis/scaler
v0.1.5
Published
Adapt content to the screen size for various occasions.
Downloads
7
Readme
Scaler
一个短小的工具库,可以将前端界面依据窗口大小进行自适应调整。
Usage
托管整屏自适应。
import {
Scaler,
MODE_NORMAL, // 自适应居中
MODE_WIDTH, // 依据宽度自适应
MODE_HEIGHT, // 依据高度自适应
MODE_FULL, // 全屏拉伸
MODE_NONE, // 不做任何处理
MODE_DEBUG // 按住shift建双击屏幕任何位置,可在自适应居中与100%中进行切换
} from '@jusfoun-vis/scaler';
const scaler = new Scaler(MODE_NORMAL, 1920, 1080);
scaler.manage();
获取100%状态下的屏幕坐标。
import {
getLocalPosition,
getGlobalPosition
} from '@jusfoun-vis/scaler';
window.onclick = function (mouseEvent) {
// 依据MouseEvent获得100%状态下的全局坐标位置
let p0 = getGlobalPosition(mouseEvent);
console.log(p0);
// 依据MouseEvent获得100%状态下相对于指定HTMLElement的坐标位置
let p1 = getLocalPosition(mouseEvent, domElement);
console.log(p1);
};