lib-flexible和postcss-px2rem PC端和移动端的适配 (PC端的设计稿1920,移动端的设计稿750)

2024-02-28 01:20

本文主要是介绍lib-flexible和postcss-px2rem PC端和移动端的适配 (PC端的设计稿1920,移动端的设计稿750),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

之前ui 给pc端的设计稿是 1920* 1080 ,并没有提过要写移动端网站,所以之前一直做的是pc端。

1,安装 flexible和 postcss-px2rem(命令行安装)

npm install lib-flexible --savenpm install postcss-px2rem --save

vue.confit.js的文件中:

在node_modules 找到 lib-flexible文件下的flexible.js,然后找到refreshRem函数,将其改为:

那么pc端的适配就好了

后来又在这的基础上要加入移动端的适配,并且UI给的移动端设计图是750,额鹅鹅鹅,而pc端的是1920,在网上查了,好像没找到 怎么同事解决给1920的设计稿和750的设计稿,最终自己摸索了会,将lib-flexible文件下的flexible.js,然后找到refreshRem函数改为:

    function refreshRem(){

        console.log('将根据已有的meta标签来设置缩放比例',win)

        var width = docEl.getBoundingClientRect().width;

        if (width / dpr > 540) {

            width = width * dpr;

        }

        

        let flag = win.navigator.userAgent.match(

            /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i

        );

        if(flag === null) {

            console.log("pc端");

            var rem = width / 10;

           

        }else {

            console.log("移动端");

            var rem = (width / 10)*2.56;   // 移动端的2.56 是 我用  192 /75 = 2.56  然后移动端的尺寸就可以1:1 进行

            

        }

        docEl.style.fontSize = rem + 'px';

        flexible.rem = win.rem = rem;

    }

《----------------------------------------------------------》

然后 首页:

<template>

  <div class="home" >

    <div v-if="type" class="homePC">

      <div class="headerNav" v-if="type">

        <div class="logo">

          <img src="@/assets/images/home/logo.png" alt="">

        </div>

        <ul class="titleNav">

          <router-link :to=item.routerName tag="li" v-for="(item,index) in  navList" :key="index" class="title">{{item.name}}</router-link>

        </ul>

    </div>

    <div>

      <router-view></router-view>

    </div>

    <div :class="$route.path==='/developmentCenter' || $route.path==='/developmentCloud'?'footer footDevelopment':$route.path==='/index'?'footer footIndex':'footer'" >

      <div><a href="#" target="_blank" class="beian">陕ICP备*****号-1</a></div>

      <div class="titleFoot">陕西****科技有限公司</div>

    </div>

    </div>

    <div v-if="!type" class="homeMobile">

      <div class="mobileHeaderNav">

        <div class="mobileNav">

          <img src="@/assets/mobileImages/home/icoNav.png" alt="" @click="mobileNavClick">

        </div>

        <div class="mobileLogo">

          <img src="@/assets/mobileImages/home/logo.png" alt="">

        </div>

        <div class="mobileNavContent" v-show="navHalfMobile" @click="navLiClick">

          <ul class="mobileUl" >

            <router-link tag="li" v-for="(item,i) in navListMobile" :key="i" :to=item.routerName @click="navLiClick">

              <div class="mobileIclPadding">

                <img :src="item.ico" alt="" :class="'mobileImg'+i">

              </div>

              <div class="mobileTitle">{{item.title}}</div>

            </router-link>

          </ul>

        </div>

      </div>

      <div>

      <router-view></router-view>

    </div>

    <!-- class="mbileFooter" -->

    <div  :class="$route.path==='/index' || $route.path==='/mobileDevelopment' || $route.path==='/mobileDevelopmentCloud'?'mbileFooter mbileFooterBack':'mbileFooter'">

      <a href="#" target="_blank" class="beianMobile">陕ICP备*****号-1</a>

      <div class="companyMobile">陕西****科技有限公司</div>

    </div>

      

    </div>

  </div>

  

</template>

<script>

export default {

  name: 'Home',

   data () {

    return {

        // value1: 0,

        navList:[

          {

            name:'首页',

            routerName:'index'

          },

          {

            name:'研发中心',

             routerName:'developmentCenter'

          },

          {

            name:'国科学院',

             routerName:'academySciences'

          },

          {

            name:'产品中心',

             routerName:'productCenter'

          },

          {

            name:'开发云',

             routerName:'developmentCloud'

          },

          {

            name:'专家团队',

             routerName:'expertTeam'

          },

          {

            name:'联系我们',

            routerName:'contactUs'

          }

        ],

         navListMobileRouter:[

          {

            name:'首页',

            routerName:'index'

          },

          {

            name:'研发中心',

             routerName:'mobileDevelopment'

          },

          {

            name:'国科学院',

             routerName:'academySciences'

          },

          {

            name:'产品中心',

             routerName:'productCenter'

          },

          {

            name:'开发云',

             routerName:'developmentCloud'

          },

          {

            name:'专家团队',

             routerName:'expertTeam'

          },

          {

            name:'联系我们',

             routerName:'contactUs'

          }

        ],

        navListMobile:[

           {

            ico:require('@/assets/mobileImages/home/homeIco.png'),

            title:'首页',

             routerName:'index'

          },{

            ico:require('@/assets/mobileImages/home/developmentIco.png'),

            title:'研发中心',

            routerName:'mobileDevelopment'

          }, {

            ico:require('@/assets/mobileImages/home/academyIco.png'),

            title:'国科学院',

            routerName:'mobileAcademySciencest'

          }, {

            ico:require('@/assets/mobileImages/home/developmentIco.png'),

            title:'产品中心',

            routerName:'mobileProductCenter'

          }, {

            ico:require('@/assets/mobileImages/home/cloudIco.png'),

            title:'开发云',

            routerName:'mobileDevelopmentCloud'

          }, {

            ico:require('@/assets/mobileImages/home/experIco.png'),

            title:'专家团队',

            routerName:'mobileexpertTeam'

          }, {

            ico:require('@/assets/mobileImages/home/contactIco.png'),

            title:'联系我们',

            routerName:'contactUs'

          }

        ],

        type:true,

        navHalfMobile:false

    }

  },

  created() {

    console.log(navigator.userAgent)

        let flag = navigator.userAgent.match(

        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i

    );

    console.log('66666666666666666',flag);

    if(flag === null) {

        console.log("pc端");

        this.type = true

       

    }else {

        console.log("移动端");

        this.type = false

        

    }

  },

  methods:{

    mobileNavClick() {

      this.navHalfMobile = true

    },

    navLiClick() {

      setTimeout(() => {

        this.navHalfMobile = false

      },500)

      

    }

  }

}

</script>

由于首页路面涉及到重定向,所以首页的pc端和移动端我写在了一个页面,剩下的页面可以和pc端分开写

这篇关于lib-flexible和postcss-px2rem PC端和移动端的适配 (PC端的设计稿1920,移动端的设计稿750)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/754094

相关文章

Springboot3统一返回类设计全过程(从问题到实现)

《Springboot3统一返回类设计全过程(从问题到实现)》文章介绍了如何在SpringBoot3中设计一个统一返回类,以实现前后端接口返回格式的一致性,该类包含状态码、描述信息、业务数据和时间戳,... 目录Spring Boot 3 统一返回类设计:从问题到实现一、核心需求:统一返回类要解决什么问题?

SpringBoot返回文件让前端下载的几种方式

《SpringBoot返回文件让前端下载的几种方式》文章介绍了开发中文件下载的两种常见解决方案,并详细描述了通过后端进行下载的原理和步骤,包括一次性读取到内存和分块写入响应输出流两种方法,此外,还提供... 目录01 背景02 一次性读取到内存,通过响应输出流输出到前端02 将文件流通过循环写入到响应输出流

SpringBoot+Vue3整合SSE实现实时消息推送功能

《SpringBoot+Vue3整合SSE实现实时消息推送功能》在日常开发中,我们经常需要实现实时消息推送的功能,这篇文章将基于SpringBoot和Vue3来简单实现一个入门级的例子,下面小编就和大... 目录前言先大概介绍下SSE后端实现(SpringBoot)前端实现(vue3)1. 数据类型定义2.

使用Python实现在PDF中添加、导入、复制、移动与删除页面

《使用Python实现在PDF中添加、导入、复制、移动与删除页面》在日常办公和自动化任务中,我们经常需要对PDF文件进行页面级的编辑,使用Python,你可以轻松实现这些操作,而无需依赖AdobeAc... 目录1. 向 PDF 添加空白页2. 从另一个 PDF 导入页面3. 删除 PDF 中的页面4. 在

前端Visual Studio Code安装配置教程之下载、汉化、常用组件及基本操作

《前端VisualStudioCode安装配置教程之下载、汉化、常用组件及基本操作》VisualStudioCode是微软推出的一个强大的代码编辑器,功能强大,操作简单便捷,还有着良好的用户界面,... 目录一、Visual Studio Code下载二、汉化三、常用组件1、Auto Rename Tag2

vite搭建vue3项目的搭建步骤

《vite搭建vue3项目的搭建步骤》本文主要介绍了vite搭建vue3项目的搭建步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录1.确保Nodejs环境2.使用vite-cli工具3.进入项目安装依赖1.确保Nodejs环境

Nginx搭建前端本地预览环境的完整步骤教学

《Nginx搭建前端本地预览环境的完整步骤教学》这篇文章主要为大家详细介绍了Nginx搭建前端本地预览环境的完整步骤教学,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录项目目录结构核心配置文件:nginx.conf脚本化操作:nginx.shnpm 脚本集成总结:对前端的意义很多

前端缓存策略的自解方案全解析

《前端缓存策略的自解方案全解析》缓存从来都是前端的一个痛点,很多前端搞不清楚缓存到底是何物,:本文主要介绍前端缓存的自解方案,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录一、为什么“清缓存”成了技术圈的梗二、先给缓存“把个脉”:浏览器到底缓存了谁?三、设计思路:把“发版”做成“自愈”四、代码

通过React实现页面的无限滚动效果

《通过React实现页面的无限滚动效果》今天我们来聊聊无限滚动这个现代Web开发中不可或缺的技术,无论你是刷微博、逛知乎还是看脚本,无限滚动都已经渗透到我们日常的浏览体验中,那么,如何优雅地实现它呢?... 目录1. 早期的解决方案2. 交叉观察者:IntersectionObserver2.1 Inter

Vue3视频播放组件 vue3-video-play使用方式

《Vue3视频播放组件vue3-video-play使用方式》vue3-video-play是Vue3的视频播放组件,基于原生video标签开发,支持MP4和HLS流,提供全局/局部引入方式,可监听... 目录一、安装二、全局引入三、局部引入四、基本使用五、事件监听六、播放 HLS 流七、更多功能总结在 v