当前位置:   article > 正文

可视化大屏比例

可视化大屏比例
  1. <!-- 数据大屏展示内容区域 -->
  2. <div class="container">
  3. <div class="screen" ref="screen">
  4. </div>
  5. </div>

screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)` 

  1. //获取数据大屏展示内容盒子的DOM元素
  2. let screen = ref()
  3. onMounted(() => {
  4. screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
  5. })
  6. //定义大屏缩放比例
  7. function getScale(w = 1920, h = 1080) {
  8. const ww = window.innerWidth / w
  9. const wh = window.innerHeight / h
  10. return ww < wh ? ww : wh
  11. }
  12. //监听视口变化
  13. window.onresize = () => {
  14. screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
  15. }
  1. .container {
  2. width: 100vw;
  3. height: 100vh;
  4. background: url("./images/bg.png") no-repeat;
  5. background-size: cover;
  6. }
  7. .screen {
  8. position: fixed;
  9. width: 1920px;
  10. height: 1080px;
  11. left: 50%;
  12. top: 50%;
  13. transform-origin: left top;
  14. }

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号