当前位置: 首页 > news >正文

大屏幕自适应

在这里插入图片描述

vue2框架

<template><div class="container"><divclass="ScaleBox"ref="ScaleBox":style="{width: width + 'px',height: height + 'px',}"><div class="contain"><div id="Stereoscopic-supervision"><div style="color: #fff; font-size: 16px;">大屏内容</div></div></div></div></div>
</template><script>
export default {data() {return {width: screen.availWidth,height: screen.availHeight,scale: 0,scaleHeight: 0,widthHeightScale: 0,};},mounted() {this.widthHeightScale = 2000 / screen.availWidth;this.setScale();window.addEventListener("resize", this.debounce(this.setScale));},methods: {toUserInfoIndex() {this.$refs.modalUserInfo.show();},//#region  自适应缩放getScale() {this.width = screen.availWidth * (this.widthHeightScale + 0.1);const { width, height } = this;const ww = window.innerWidth / width;return ww;},getScaleHeight() {this.height = screen.availHeight * this.widthHeightScale;const { width, height } = this;const wh = window.innerHeight / height;return wh;},setScale() {// 获取到缩放比例,设置它this.scale = this.getScale();this.scaleHeight = this.getScaleHeight();if (this.$refs.ScaleBox) {this.$refs.ScaleBox.style.setProperty("--scale", this.scale);this.$refs.ScaleBox.style.setProperty("--scaleHeight",this.scaleHeight);}},debounce(fn, delay) {const delays = delay || 500;let timer;return function () {const th = this;const args = arguments;if (timer) {clearTimeout(timer);}timer = setTimeout(function () {timer = null;fn.apply(th, args);}, delays);};}},
};
</script><style lang="scss" scoped>.ScaleBox {display: flex;transform: scale(var(--scale, 1), var(--scaleHeight, 1));transform-origin: 0 0;// 设计稿宽高width: 100vw;height: 100vh;
}.contain {width: 100%;height: 100%;overflow: auto;
}#Stereoscopic-supervision {  // 背景图min-height: 100%;background-image: url("/img/bm/StereoscopicSupervision/background.png");background-repeat: no-repeat;background-size: 100% 100%;font-size: 12px;position: relative;
}
.contain::-webkit-scrollbar {display: none;
}
</style>

react框架

jsx文件

import React, { useState, useEffect, useRef } from 'react';
import './App.css'; // 创建对应的 CSS 文件const ScaleBox = () => {const scaleBoxRef = useRef(null);const [dimensions, setDimensions] = useState({width: window.screen.availWidth,height: window.screen.availHeight,scale: 1,scaleHeight: 1,widthHeightScale: 2000 / window.screen.availWidth});const getScale = () => {const width = window.screen.availWidth * (dimensions.widthHeightScale + 0.1);const ww = window.innerWidth / width;return ww;};const getScaleHeight = () => {const height = window.screen.availHeight * dimensions.widthHeightScale;const wh = window.innerHeight / height;return wh;};const setScale = () => {const newScale = getScale();const newScaleHeight = getScaleHeight();setDimensions(prev => ({...prev,scale: newScale,scaleHeight: newScaleHeight}));if (scaleBoxRef.current) {scaleBoxRef.current.style.setProperty('--scale', newScale);scaleBoxRef.current.style.setProperty('--scaleHeight', newScaleHeight);}};const debounce = (fn, delay) => {const delays = delay || 500;let timer;return function () {const th = this;const args = arguments;if (timer) {clearTimeout(timer);}timer = setTimeout(function () {timer = null;fn.apply(th, args);}, delays);};};useEffect(() => {setScale();const debouncedHandleResize = debounce(setScale, 500);window.addEventListener('resize', debouncedHandleResize);return () => {window.removeEventListener('resize', debouncedHandleResize);};}, []);return (<div className="container"><divclassName="ScaleBox"ref={scaleBoxRef}style={{width: `${dimensions.width}px`,height: `${dimensions.height}px`,'--scale': dimensions.scale,'--scaleHeight': dimensions.scaleHeight}}><div className="contain"><div id="Stereoscopic-supervision"><div style={{ color: '#fff', fontSize: '16px' }}>大屏内容</div></div></div></div></div>);
};export default ScaleBox;

scss文件

.ScaleBox {display: flex;transform: scale(var(--scale, 1), var(--scaleHeight, 1));transform-origin: 0 0;/* 设计稿宽高 */width: 100vw;height: 100vh;
}.contain {width: 100%;height: 100%;overflow: auto;
}#Stereoscopic-supervision {  /* 背景图 */min-height: 100%;background-image: url("/img/bm/StereoscopicSupervision/background.png");background-repeat: no-repeat;background-size: 100% 100%;font-size: 12px;position: relative;
}.contain::-webkit-scrollbar {display: none;
}
http://www.dtcms.com/a/326419.html

相关文章:

  • 基于FPGA的热电偶测温数据采集系统,替代NI的产品(三)测试
  • C++ STL | STL迭代器(lterator)
  • 阿里千问系列:Qwen3 强化学习新算法GSPO!
  • HTML应用指南:利用GET请求获取全国一加授权零售店位置信息
  • 机器学习逻辑回归实战
  • 【Lua】题目小练10
  • computed使用的方式
  • 【Lua】XLua加载lua文件
  • xlsxio全平台(x86、arm32、arm64 )编译、测试,使用编译脚本10分钟快速编译!
  • redis常见的性能问题
  • 游戏盾是什么?
  • Qwen Code CLI在Windows上的安装与环境配置问题解决
  • 金蝶云星辰:赋能企业数据管理
  • 开发指南130-实体类的主键生成策略
  • 达梦数据库慢SQL日志收集和分析
  • 机器学习 TF-IDF提取关键词,从原理到实践的文本特征提取利器​
  • Java 之抽象类和接口
  • 数据结构-数组扩容
  • 2025苹果CMS泛目录 8月最新可用
  • 软件测评中HTTP 安全头的配置与测试规范
  • 鸿蒙开发中所有自定义装饰器的完整案例解析--涵盖 16 个核心装饰器的详细用法和实战场景
  • QT 高分屏不同缩放比例的自适应处理
  • 数据科学与计算实例应用
  • 借助 ChatGPT 快速实现 TinyMCE 段落间距与行间距调节
  • Ansible 面试题 20250811
  • OpenGL中的EBO:高效渲染的秘密武器(绘制四边形)(Unreal Engine、Unity、Godot原理系列)
  • JavaScript中map和forEach的区别详解
  • 动捕设备是什么?全面解析NOKOV度量动捕设备的原理、类型与应用
  • redis(1)-基本概念
  • ROS2不同版本的区别