<div class="scale-box" :style="{ transform: `scale(${scaleX},${scaleY}) translate(-50%, -50%)` }" ></div>
// 这是包裹元素 最外层的 利用 css3 动画属性 transform 整体页面进行 缩放缩小
<style>
.scale-box {
width: 1920px;
height: 1080px;
transform-origin: 0 0;
position: absolute;
left: 50%;
top: 50%;
transition: 0.3s;
overflow: hidden;
}
</style>
mounted() {
this.styleScale()
},
methods: {
styleScale(){
let that = this;
console.log(111111)
window.addEventListener('resize', this.setScale);
window.addEventListener('keydown', function(e) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && e.keyCode == 122) {
//捕捉F11键盘动作
e.preventDefault(); //阻止F11默认动作
var el = document.documentElement;
var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen; //定义不同浏览器的全屏API //执行全屏
if (typeof rfs != 'undefined' && rfs) {
rfs.call(el);
} else if (typeof window.ActiveXObject != 'undefined') {
var wscript = new ActiveXObject('WScript.Shell');
if (wscript != null) {
wscript.SendKeys('{F11}');
}
}
const weListenScreen = function() {
if (document.webkitIsFullScreen) {
// console.log(1)
that.flag = true; // 全屏
console.log(that.flag, '全屏');
that.setScale();
} else {
that.flag = false; // 不全屏
console.log(that.flag, '不全屏');
that.setScale();
// console.log(2)
document.addEventListener('webkitfullscreenchange', weListenScreen);
}
};
document.addEventListener('webkitfullscreenchange', weListenScreen, false);
}
});
this.flag = false;
this.setScale();
},
getScale() {
// 固定好16:9的宽高比,计算出最合适的缩放比,宽高比可根据需要自行更改
let ww = window.innerWidth / 1920;
let wh = window.innerHeight / 1080;
return ww < wh ? ww : wh;
},
setScale() {
var ratio = 0,
screen = window.screen,
ua = navigator.userAgent.toLowerCase();
if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio;
} else if (~ua.indexOf('msie')) {
if (screen.deviceXDPI && screen.logicalXDPI) {
ratio = screen.deviceXDPI / screen.logicalXDPI;
}
} else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
ratio = window.outerWidth / window.innerWidth;
}
if (ratio) {
ratio = Math.round(ratio * 100); // 计算浏览器百分比缩放
}
console.log(ratio)
if (this.flag) {
this.scaleX = this.getScale();
this.scaleY = this.getScale();
console.log(this.flag, 1);
} else { // 根据屏幕大小自适应 适应任何屏幕 但是会留黑边 只有在F11 全屏下 才能铺满屏幕
console.log(this.flag, 2);
this.scaleX = this.getScale();
this.scaleY = this.getScale();
return
// 下面这个根据 屏幕大小自定缩放比例 能占满全屏 不是F11 全屏状态下 会有压缩 圆形会变形
switch (window.screen.availWidth) {
case 1920:
switch (ratio) {
case 175:
this.scaleX = 0.575;
this.scaleY = 0.49537;
break;
case 150:
this.scaleX = 0.67;
this.scaleY = 0.578704;
break;
case 125:
this.scaleX = 0.799999;
this.scaleY = 0.694444;
break;
case 110:
this.scaleX = 0.91;
this.scaleY = 0.788889;
break;
case 100:
this.scaleX = 1;
this.scaleY = 0.867593;
break;
case 90:
this.scaleX = 1.1111;
this.scaleY = 0.963889;
break;
case 80:
this.scaleX = 1.24999;
this.scaleY = 1.08426;
break;
case 75:
this.scaleX = 1.33333;
this.scaleY = 1.15648;
break;
default:
this.scaleX = this.getScale();
this.scaleY = this.getScale();
}
break;
case 1366:
switch (ratio) {
case 175:
this.scaleX = 0.575;
this.scaleY = 0.49537;
break;
case 150:
this.scaleX = 0.4744;
this.scaleY = 0.386111;
break;
case 125:
this.scaleX = 0.57;
this.scaleY = 0.462963;
break;
case 110:
this.scaleX = 0.648;
this.scaleY = 0.525926;
break;
case 100:
this.scaleX = 0.712;
this.scaleY = 0.5898704;
break;
case 90:
this.scaleX = 0.791;
this.scaleY = 0.642593;
break;
case 80:
this.scaleX = 0.89;
this.scaleY = 0.723148;
break;
case 75:
this.scaleX = 0.949;
this.scaleY = 0.771296;
break;
default:
this.scaleX = this.getScale();
this.scaleY = this.getScale();
}
break;
case 1360:
switch (ratio) {
case 175:
this.scaleX = 0.575;
this.scaleY = 0.49537;
break;
case 150:
this.scaleX = 0.4744;
this.scaleY = 0.386111;
break;
case 125:
this.scaleX = 0.57;
this.scaleY = 0.462963;
break;
case 110:
this.scaleX = 0.648;
this.scaleY = 0.525926;
break;
case 100:
this.scaleX = 0.712;
this.scaleY = 0.5898704;
break;
case 90:
this.scaleX = 0.791;
this.scaleY = 0.642593;
break;
case 80:
this.scaleX = 0.89;
this.scaleY = 0.723148;
break;
case 75:
this.scaleX = 0.949;
this.scaleY = 0.771296;
break;
default:
this.scaleX = this.getScale();
this.scaleY = this.getScale();
}
break;
default: // 按着 1680 分辨率调的
switch (ratio) {
case 175:
this.scaleX = 0.50;
this.scaleY = 0.47537;
break;
case 150:
this.scaleX = 0.58144;
this.scaleY = 0.5386111;
break;
case 125:
this.scaleX = 0.6948;
this.scaleY = 0.6648;
break;
case 110:
this.scaleX = 0.7948;
this.scaleY = 0.7725926;
break;
case 100:
this.scaleX = 0.872;
this.scaleY = 0.81987;
break;
case 90:
this.scaleX = 0.9691;
this.scaleY = 0.942593;
break;
case 80:
this.scaleX = 1.0911;
this.scaleY = 1.02923148;
break;
case 75:
this.scaleX = 1.162911;
this.scaleY = 1.0911;
break;
default:
this.scaleX = this.getScale();
this.scaleY = this.getScale();
}
}
}
// console.log(ratio);
}
},
vue 大屏自适应
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Vue大屏项目自适应--响应式盒子 一、获取当前浏览器可视窗口宽高 1、在Vue项目 src文件夹内新建 util...
- 配置前言 项目构建:基于vue-cli3构建,使用postcss-px2rem px2rem-loader进行re...
- 数据可视化 将数据通过各种视觉通道映射成图形,可以使得用户更快、更准确的理解数据。 大屏用途 用于公司展厅、日常经...