大屏自适应解决方案(手写js)

一、插件v-scale-screen

地址前端可视化大屏适配方案_前端大屏适配方案 vw vh 适配方案,当浏览器窗口变动时 实时适配-CSDN博客

二、

使用方法

javascript 复制代码
<div id="app"></div>
<script type="module" src="/src/main.ts">
import { autoScale } from './autoScale.js'
autoScale('#app', {
  width: 1920,
  height: 1080
})
  </script>

autoScale.js

javascript 复制代码
function debounce(fn, delay) {
let timer
return function () {
clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(this, arguments);
}, delay);
};
}

export function autoScale(selector,options) {
const el = document.querySelector(selector);
const {width,height} = options; 

el.style.transformOrigin = "top left";
el.style.transition = "transform 0.5s"
function init(){
const scaleX = innerWidth / width
const scaleY = innerHeight / height
const scale = Math.min(scaleX, scaleY);

const left = (innerWidth - width * scale) / 2
const top = (innerHeight - height * scale) / 2
el.style.transform = ` translate(${left}px,${top}px) scale(${scale})`
}
init()
addEventListener("resize", debounce(init,200))
}
相关推荐
Csvn13 小时前
🛡️ 前端水印方案全解析——从「能被 F12 删掉」到「删不掉」的反破解实战
前端
学网安的肆伍14 小时前
【046-WEB攻防篇】注入工具&SQLMAP&Tamper编写&指纹修改&高权限操作&目录架构
前端·架构
森林的尽头是阳光14 小时前
tree回显问题
javascript·vue.js·elementui
weixin_BYSJ198715 小时前
「课设设计」springboot校园超市助购系统26449 (附源码)
java·javascript·spring boot·python·django·flask·php
Highcharts.js15 小时前
如何下载使用Highcharts Grid 开发web可编辑表格
前端·人工智能·grid 表格·web 表格·在线编辑表格·highcharts表格安装·表格开发工具
用户629605932470516 小时前
从“浏览器根本区分不了”到真正实现:刷新不退出,关闭标签页自动退出,前端判断浏览器关闭和刷新
前端
qetfw16 小时前
MWU:Vue 3 + FastAPI 的 MaaFramework 跨平台 WebUI 源码
前端·vue.js·python·fastapi·开源项目·效率工具
mfxcyh16 小时前
Vue3+Ant Design Vue 实现手动异步文件上传(含大小校验、弹窗上传)
前端·javascript·vue.js
wordbaby16 小时前
Web端热敏标签打印完整解决方案(QZ Tray + 译维A42)
前端
swipe16 小时前
03|Axios 请求进了后端之后:Controller、Request、Response 是怎么接住它的?
前端·后端·全栈