大屏适配window.onresize监听窗口变化,该方法已用于生产

摘要:
1js部分//此开发方案2880*1080与css2mounted(){3this.pageResize()4window.reze=()=˃{5setTimeout(()=˃{6this.pageSize()7},200)8}9},10方法:{11 pageResize){12//*默认缩放值为13letscale={14'1',15height:'1'16}1
 1 js部分  // 本次开发场景2880*1080  配合css
 2     mounted () {
 3         this.pageResize()
 4         window.onresize = () => {
 5             setTimeout(() => {
 6                 this.pageResize()
 7             }, 200)
 8         }
 9     },
10      methods:{
11      pageResize () {
12             // * 默认缩放值
13             let scale = {
14                  '1',
15                 height: '1'
16             }
17             // * 设计稿尺寸(px)根据实际修改
18             let baseWidth = 2880
19             let baseHeight = 1080
20             // * 需保持的比例(默认2.66667)
21             const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5))
22             // 当前宽高比
23             const currentRate = parseFloat(
24                 (window.innerWidth / window.innerHeight).toFixed(5)
25             )
26             if (currentRate > baseProportion) {
27                 // 表示更宽
28                 scale.width = (
29                     (window.innerHeight * baseProportion) /
30                     baseWidth
31                 ).toFixed(5)
32                 scale.height = (window.innerHeight / baseHeight).toFixed(5)
33                 this.$refs.appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
34             } else {
35                 // 表示更高
36                 scale.height = (
37                     window.innerWidth /
38                     baseProportion /
39                     baseHeight
40                 ).toFixed(5)
41                 scale.width = (window.innerWidth / baseWidth).toFixed(5)
42                 this.$refs.appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
43             }
44         },       
45 }
 1 HTML
 2 <template>
 3     <div id="main_box" ref="appRef" class="main_box_0121">
 4         <div class="bg">
 5             <div class="head"></div>
 6              <div class="content_left"></div>
 7              <div class="content_center"></div>
 8             <div class="content_right"></div>
 9         </div>
10     </div>
11 </template>                    
 1 CSS
 2 #main_box {
 3     position: absolute;
 4     top: 50%;
 5     left: 50%;
 6     width: 2880px;
 7     height: 1080px;
 8     transform: translate(-50%, -50%);
 9     transform-origin: left top;
10 
11     .bg {
12         position: relative;
13         width: 100%;
14         height: 100%;
15         background-image: url('../../assets/pageBg.jpg');
16         background-position: center center;
17         background-size: cover;
18         //标题
19         .head {
20             width: 100%;
21             height: 85px;
22             background: url('../../assets/head.png') no-repeat;
23             background-position: center center;
24             background-size: 100% 100%;
25             z-index: 100;
26         }
27         // left
28         .content_left {
29             position: absolute;
30             top: 58px;
31             width: 14.5%;
32             height: 1000px;
33             padding: 35px 0.5% 0 0.9%;
34             margin: 0 0.5%;
35             background: url('../../assets/left.png')  no-repeat;
36             background-position: center center;
37             background-size: 100% 100%;
38            }
39         .content_center {
40             position: absolute;
41             top: 72px;
42             left: 15.8%;
43             width: 83.5%;
44             height: 960px;
45             background: url('../../assets/bg2.png') no-repeat;
46             background-position: center center;
47             background-size: 100% 100%;
48         }
49         //right
50         .content_right {
51             position: absolute;
52             top: 82px;
53             right: 1.1%;
54             width: 30.3%;
55             height: 940px;
56             padding: 30px 40px 20px 50px;
57             background: url('../../assets/right.png') no-repeat;
58             background-position: center center;
59             background-size: 100% 100%;
60      }
   }

 案例 https://cloud.njkshb.com:92/bigScreen

大屏适配window.onresize监听窗口变化,该方法已用于生产第1张

免责声明:文章转载自《大屏适配window.onresize监听窗口变化,该方法已用于生产》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇部署水晶报表的打包安装centos7 安装 smplayer下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

移动端兼容性问题解决方案

1. IOS移动端click事件300ms的延迟响应 移动设备上的web网页是有300ms延迟的,往往会造成按钮点击延迟甚至是点击失效。这是由于区分单击事件和双击屏幕缩放的历史原因造成的, 2007年苹果发布首款iphone上IOS系统搭载的safari为了将适用于PC端上大屏幕的网页能比较好的展示在手机端上,使用了双击缩放(double tap to z...

巧用伪元素绘制带边的三角形--CSS3

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title></title> <meta name="description"content=""> <meta name="author"...

解决绝对定位div position: absolute 后面的&amp;lt;a&amp;gt; Link不能点击

今天布局的时候,遇到一个bug,当DIV设置为绝对定位时,这个div后面的相对定位的层里面的<a>Link标签无法点击。 网上的解决方案是在绝对定位层里面添加:pointer-events:none;这样能够让鼠标事件穿透这个绝对定位层,使之能点击到后面的<a>,然后再在这个绝对定位层里面需要接受事件的<a>上面添加:p...

学习HTML5获取地理位置定位信息--(通过百度地图API,google地图API的两种方式)

前言:它是依赖于 百度地图API或google地图API 的功能,并且要允许定位; 思想:h5方式仅能获取到经纬度,通过得到的经纬度然后ajax调用百度地图和谷歌地图等提供的这方面的接口,才获取到的具体位置信息。 HTML5提供了地理位置定位功能(Geolocation API),能确定用户位置,我们可以借助HTML5的该特性开发基于地理位置信息的应用。本...

CSS躬行记(8)——裁剪和遮罩

一、 裁剪 裁剪(clipping)能让元素显示指定形状的区域,在布局时可起点缀的作用,丰富了视觉呈现。注意,裁剪本质上只是让元素的部分区域透明,由此可知,裁剪完后元素所占的空间仍旧会保留。裁剪最早是在CSS 2.1时代由clip属性引入,但该属性只能应用于绝对定位的元素,并且只能裁剪成矩形。CSS3提供了强大的clip-path属性,突破了clip属性的...

Android—简单的仿QQ聊天界面

最近仿照QQ聊天做了一个类似界面,先看下界面组成(画面不太美凑合凑合呗,,,,):     其中聊天背景可以是一个LinearLayout或者RelativeLayout里面存放的是ListView(将ListView的分割线设置成透明:android:divider="#0000"否则聊天界面会显示出分割线,,,想想都屌,,,)    于是,我要上主界...