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

大屏自适应方案

大屏自适应方案

参考:http://xmduanru.com/#/dataScreen

<script lang="ts" setup>
import { ref, onMounted, onBeforeUnmount } from "vue";const dataScreenRef = ref<HTMLElement | null>(null);
function handelScreenAuto() {if (dataScreenRef.value) {dataScreenRef.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;dataScreenRef.value.style.width = `1920px`;dataScreenRef.value.style.height = `1080px`;}window.addEventListener("resize", resize);
}function resize() {if (dataScreenRef.value) {dataScreenRef.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;}
}function getScale() {const width = 1920;const height = 1080;let ww = window.innerWidth / width;let wh = window.innerHeight / height;return ww < wh ? ww : wh;
}
onMounted(() => {handelScreenAuto();
});
onBeforeUnmount(() => {window.removeEventListener("resize", resize);
});
</script>
<template><div class="screen-wrapper"><div class="screen-main" id="screen" ref="dataScreenRef"><home-head></home-head><home-main></home-main><home-footer></home-footer></div></div>
</template><style lang="scss" scoped>
.screen-wrapper {height: 100%;width: 100%;background-color: #fff;position: relative;background: url("../assets/image/bg.png");background-repeat: no-repeat;background-attachment: fixed;background-position: center;background-size: 100% 100%;background-size: cover;.screen-main {width: 100%;height: 100%;box-sizing: border-box;transition: all 0.1s;transform-origin: 0 0;position: fixed;top: 50%;left: 50%;z-index: 999;overflow: hidden;}
}

background-attachment 属性用于控制背景图像的滚动行为。它有三个值:

  1. scroll:背景图像随内容滚动(默认值)。
  2. fixed:背景图像固定在视口,内容滚动时背景不动。
  3. local:背景图像随内容的滚动而滚动,但只在元素的内部滚动区域。

http://www.mrgr.cn/news/36591.html

相关文章:

  • MongoDB学习
  • 深度学习之开发环境(CUDA、Conda、Pytorch)准备(4)
  • Redis学习
  • antd嵌套表单验证
  • 请问,项目经理们,PMP证书有用吗?
  • 2024中国新能源汽车零部件交易会,开源网安展示了什么?
  • Dbt自动化测试实战教程
  • 在大模型应用层面区分对比检索增强生成RAG技术和知识库技术
  • Android 系统增加ro property
  • 基于Dockerfile打包算法镜像
  • vue-i18n在使用$t时提示类型错误
  • Jupyter Neo4j
  • Ansible-使用roles
  • C语言⾃定义类型:结构体
  • mysql数据库:超键、候选键、主键与外键
  • 【GreenHills】使用“gsrec”命令生成二进制文件
  • 什么是秒传,代码
  • 对 AI 产品定价模式的新思考:基于人数 or 工作量?
  • TLS(Transport Layer Security)是一种加密协议,用于在互联网通信中保护数据的安全性。
  • SQL优化系列-有索引,为什么查询也这么慢?