欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > 【企业开发】大屏的响应式处理

【企业开发】大屏的响应式处理

2025/3/17 22:55:53 来源:https://blog.csdn.net/weixin_44224921/article/details/139438054  浏览:    关键词:【企业开发】大屏的响应式处理

【企业开发】大屏的响应式处理

如图:

在这里插入图片描述

响应式工具封装

// 等比缩放方式屏幕适配
export function screenAdaptive(designWidth = 1920, designHeight = 1080) {const screenWidth =document.documentElement.clientWidth || document.body.clientWidthconst screenHeight =document.documentElement.clientHeight || document.body.clientHeightconst scaleX = screenWidth / designWidthconst scaleY = screenHeight / designHeightconst { body } = documentbody.style.transformOrigin = 'left top'body.style.position = 'relative'body.style.width = `${designWidth}px`body.style.height = `${designHeight}px`body.style.boxSizing = 'border-box'body.style.transform = `scale(${scaleX},${scaleY})`
}// 关闭适配
export function unScreenAdaptive() {const { body } = documentbody.style.transformOrigin = ''body.style.position = ''body.style.width = '100%'body.style.height = '100%'body.style.boxSizing = ''body.style.transform = ''
}

在大屏组件中添加响应式处理

安装工具

$ pnpm add lodash

Vue组件中

<script lang="ts" setup>
import _ from 'lodash'
import { onBeforeMount, onUnmounted, watch } from 'vue'
import { screenAdaptive, unScreenAdaptive } from '@/utils/screen-adaptive'const watchScreenAdaptive = (notUninstall = true) => {if (notUninstall) {screenAdaptive(1912, 932)window.addEventListener('resize',_.throttle(() => screenAdaptive(1912, 932), 300))} else {window.removeEventListener('resize',_.throttle(() => screenAdaptive(1912, 932), 300))}
}onBeforeMount(() => watchScreenAdaptive())onUnmounted(() => {unScreenAdaptive()watchScreenAdaptive(false)
})
</script>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词