当前位置:网站首页>H5 适配全面屏
H5 适配全面屏
2022-06-23 03:56:00 【*且听风吟】
问题:最近用 vue 开发 h5 应用时,发现表单提交按钮在最下面时,iPhone 原生控件 home indicator 横条会挡住提交按钮,如下图:
所以,需要适配全面屏,在判断是全面屏时,添加定制化样式,让按钮位置往上面一点。
utils.js 中封装判断是否全面屏的工具函数:
// 检测是否为全面屏
export function checkFullScreen () {
let isFullScreen = false
const rate = window.screen.height / window.screen.width;
let limit = window.screen.height == window.screen.availHeight ? 1.8 : 1.65; // 临界判断值
// window.screen.availWidth:声明了显示浏览器的屏幕的可用宽度,以像素计。在 Windows 这样的操作系统中,这个可用高度不包括分配给半永久特性(如屏幕底部的任务栏)的垂直空间。
// window.screen.availHeight:声明了显示浏览器的屏幕的可用高度,以像素计。在 Windows 这样的操作系统中,这个可用高度不包括分配给半永久特性(如屏幕底部的任务栏)的垂直空间。
// window.screen.width:声明了显示浏览器的屏幕的宽度,以像素计。
// window.screen.height:声明了显示浏览器的屏幕的高度,以像素计。
if (rate > limit) {
isFullScreen = true;
}
return isFullScreen
}
然后,在页面引入工具函数之后使用:
<template>
<div class="btn-container" :class="{'full-screen':isFullScreen}">
<van-button :loading="submitLoading" block type="submit" color="linear-gradient(90deg, #2c2c2c 0%, #28beca 100%)" :disabled="!formData.name" native-type="submit">提交</van-button>
</div>
</template>
<script>
import {
checkFullScreen } from '@/utils/utils'
export default {
data() {
return {
submitLoading: false,
isFullScreen: checkFullScreen()
}
}
}
</script>
<style lang="less" scoped>
.full-screen {
padding-bottom: 0.42rem;
}
</style>
页面效果如下:

边栏推荐
- JDBC入门学习(四)之Druid连接池的使用
- UI automation positioning edge -xpath actual combat
- Beyond chips and AI, why is hard technology capital becoming more and more "hard core"?
- 同步国内AOSP代码相关错误
- (IntelliJ)插件一 Background Image Plus
- 如何进行探索性数据分析
- Mysql入门学习(二)之子查询+关联
- HCIP第五次作业
- Introduction and use of precise ephemeris
- 网上有真实的兼职吗?大学生怎么找暑期兼职?
猜你喜欢

大環境不好難找工作?三面阿裏,幸好做足了准備,已拿offer

99 multiplication table bat

IDEA 代码开发完毕后,提交代码,提交后发现分支不对,怎么撤回

Missing essential plugin
![Direct insertion sort - [common sort method (1/8)]](/img/c3/f08d789c9ff32dda4f20c58e7c114d.png)
Direct insertion sort - [common sort method (1/8)]

Beyond chips and AI, why is hard technology capital becoming more and more "hard core"?

HCIP第五次作业

Master shell, one article is enough!

Snippet Manager snippetslab

JSP entry notes
随机推荐
Hcip switch experiment
Onnxoptimizer, onnxsim usage records
What is the average annual salary of an outsourced tester who has worked for 5-8 years?
OSPF分流实验
Drama asking Huamen restaurant Weng
gis利器之Gdal(三)gdb数据读取
When SBAS encounters rtklib
JDBC call stored procedure, MySQL trigger
The tiobe programming language ranking is an indicator of the popular trend of programming languages
Hcip fifth operation
985 test engineer is hanged. Who is more important in terms of education and experience?
弱者易怒如虎,强者平静如水,真正厉害的人早已戒掉了情绪
搭建一套 gocd 的环境
关于信息泄露和防御
mongodb分片原理
Direct insertion sort - [common sort method (1/8)]
PRCS-1016 : Failed to resolve Single Client Access Name
SwiftUI 2.0 课程笔记 Chapter 5
IDEA 代码开发完毕后,提交代码,提交后发现分支不对,怎么撤回
C'est dur de trouver un emploi? Ali des trois côtés, heureusement qu'il s'est bien préparé et qu'il a pris un produit.