阅读:4175回复:1
css js 控制屏幕缩放,自适应所有屏幕
往往 结合 screenSize Js一起用。
HTML: <div class="wrap" ref="editor"> JS: import { screenSize } from '@/assets/js/utils' mounted() { screenSize(this.$refs.editor) } JS全文: // 屏幕缩放 export function screenSize(editorDom) { let screenWidth = document.body.clientWidth || document.documentElement.clientWidth; let screenHeight = document.body.clientHeight || document.documentElement.clientHeight; let defWidth = 1920; let defHeight = 1080; let xScale = screenWidth / defWidth; let yScale = screenHeight / defHeight; editorDom.style.cssText += ';transform: scale(' + xScale + ',' + yScale + ')'; $(window).resize(() => { let screenWidth = document.body.clientWidth || document.documentElement.clientWidth; let screenHeight = document.body.clientHeight || document.documentElement.clientHeight; xScale = screenWidth / defWidth; yScale = screenHeight / defHeight; editorDom.style.cssText += ';transform: scale(' + xScale + ',' + yScale + ')'; }) } |
|
沙发#
发布于:2022-01-21 13:48
往往需要配合CSS:
transform: scale(1,1.18); -ms-transform: scale(1,1.18); /* IE 9 */ -webkit-transform: scale(1,1.18); /* Safari 和 Chrome */ -o-transform: scale(1,1.18); /* Opera */ -moz-transform: scale(1,1.18); /* Firefox */ 一起处理样式展示问题。 |
|