当前位置:网站首页>uniapp适配问题
uniapp适配问题
2022-07-06 19:21:00 【这次我一定要赢】
原文链接:https://blog.csdn.net/weixin_52312684/article/details/125218453
一.计算公式
设计稿 1px / 设计稿基准宽度 = 框架样式 1rpx / 750rpx
换言之,页面元素宽度在 uni-app 中的宽度计算公式:
750 * 元素在设计稿中的宽度 / 设计稿基准宽度
举例说明:
- 若设计稿宽度为 750px,元素 A 在设计稿上的宽度为 100px,那么元素 A 在 uni-app 里面的宽度应该设为:750 *
100 / 750,结果为:100rpx。
- 若设计稿宽度为 640px,元素 A 在设计稿上的宽度为 100px,那么元素 A 在 uni-app 里面的宽度应该设为:750 *
100 / 640,结果为:117rpx。
- 若设计稿宽度为 375px,元素 B 在设计稿上的宽度为 200px,那么元素 B 在 uni-app 里面的宽度应该设为:750 *
200 / 375,结果为:400rpx。
二.宽度750px设计稿
更具上面的换算公式
750 * 元素在设计稿中的宽度 / 设计稿基准宽度=100rpx
设计图是100px转换成为100rpx
结论:
1px=1rpx
验证:
<template>
<view class="box">
<view class="box1">
</view>
</view>
</template>
<script>
export default {
}
</script>
<style>
.box{
width: 750rpx;
height: 1000rpx;
background-color: pink;
}
.box1{
width: 100rpx;
height: 100rpx;
background-color: blue;
}
</style>
在大屏下:

盒子的大小由100x100变成50x50
说明:
在大屏下 1px=2rpx
得出结论:
rpx能够自适应屏幕的大小 从而概念元素的尺寸。
实际开发的时候可以直接在手机模式下进行开发

二.宽度640px设计稿
先换算一下:
750x100/640=117rpx
设计稿:100:117
1:1.17
也就是说1px等于1.17rpx
100rpx/1.17=85.47

通常情况下我们一般以750px作为标准来进行开发。
三.扩展
移动端是如何做适配的呢?
1.百分比 2.rem
这里我们重点说rem
假设设计稿为980px 如何做适配
rem是一个单位它相对于当前屏幕的大小而言的。
通常用flexbox.js 这个插件来将屏幕划分成10份。
980/10=98px
也就是1rem等于98px。
代码:
<template>
<div class="box">
</div>
</template>
<script>
export default {
name: '',
methods: {
}
}
</script>
<style scoped>
.box{
width: 1rem;
height: 1rem;
background-color: pink;
}
</style>


四.思考
设计稿999px,在789px做适配转换成rem
设计稿为999px。
在手机为789px做适配。
设计稿的1rem 为 99.9px。
手机的1rem为78.9px。
得出结论:
设计稿的1px等于:78.9px/99.9px=0.789
就可以按照设计稿上的1px 等于手机上0.789px来画图了
或者用另外一种算法:

边栏推荐
- 普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
- QPushButton-》函数精解
- Software testing -- common assertions of JMeter interface testing
- Go swagger use
- Safety delivery engineer
- Leetcode:minimum_ depth_ of_ binary_ Tree solutions
- 慧通编程入门课程 - 2A闯关
- Redis入门完整教程:AOF持久化
- What management points should be paid attention to when implementing MES management system
- Qpushbutton- "function refinement"
猜你喜欢

Huitong programming introductory course - 2A breakthrough

左程云 递归+动态规划

Summary of basic debugging steps of S120 driver
![[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication](/img/09/b9d50f7a10e6898ac4088ee005d00b.png)
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication

What management points should be paid attention to when implementing MES management system

The panel floating with the mouse in unity can adapt to the size of text content

Redis入门完整教程:复制配置

Linear list --- circular linked list

Redis入门完整教程:客户端案例分析

NuScenes数据集关于Radar数据的统计
随机推荐
Qt蓝牙:QBluetoothDeviceInfo
The 8 element positioning methods of selenium that you have to know are simple and practical
Redis入门完整教程:AOF持久化
Statistics of radar data in nuscenes data set
Redis入门完整教程:复制拓扑
进程管理基础
Code debugging core step memory
Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
Cloud Mail . NET Edition
慧通编程入门课程 - 2A闯关
The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
MySQL
unity webgl自适应网页尺寸
MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)
STM32 project -- Topic sharing (part)
Django数据库(SQlite)基本入门使用教程
QT common Concepts-1
Ali yunyili: how does yunyuansheng solve the problem of reducing costs and improving efficiency?
MySQL --- 常用函数 - 字符串函数
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication