b***@163.com
b***@163.com
  • 发布:2019-10-24 10:59
  • 更新:2020-05-25 14:34
  • 阅读:1164

怎么让rpx upx在pc上固定大小

分类:uni-app

项目开发完了,突然加需求要求适配pc端,目前做的是固定了一个大小居中,但是由于项目用的是upx rpx导致页面很多元素变形,请问有方法让rpx upx 在pc上固定大小吗或者根据html body来自适应?

2019-10-24 10:59 负责人:无 分享
已邀请:
飞翔的熊猫
uniapp追随者

uniapp追随者

解决方案很简单,在自定义的h5 template文件head中,修改<script></script>中的代码:

<script>  
    document.addEventListener('DOMContentLoaded', function() {  
        // #ifdef H5  
        window.innerWidth = Math.min(window.innerWidth, 750)  
        document.documentElement.style.fontSize = window.innerWidth / 20 + 'px'  
        // #endif  

        // ifndef H5  
        document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'  
        // endif  
    })  
</script>

具体也可以查看这篇文章:uni-app H5 平台在 PC 端实现适配

该问题目前已经被锁定, 无法添加新回复