想用uni把已有的项目转过来,h5pc端这种效果用rpx怎么实现呢,之前用的rem。有个最大宽屏幕变大的时候不再变大,居中显示。

威风扫地飞
- 发布:2020-04-09 18:28
- 更新:2020-05-25 14:36
- 阅读:1131


解决方案很简单,在自定义的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 端实现适配