news 2026/5/21 3:40:57

uniapp输入框fixed定位,导致页面顶起解决方案

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
uniapp输入框fixed定位,导致页面顶起解决方案

解决方案在pages页面中使用禁止页面向上顶起,设置fixed的bottom等于0即可

"app-plus": { "softinputMode": "adjustResize", }

但由于我首页页面设置禁止顶起 页面显示会错乱原因是在键盘弹起时会导致 iOS 的 viewport 收缩,进而触发页面重新计算滚动位置。

所以我ios用的textarea的@keyboardheightchange

<view @touchstart.stop="" @touchmove.stop="" @touchend.stop="" :style="{ bottom:'0px',zIndex:shareShow?'10 !important':'' }" class="inputbox"> <view :style="{ background: offsetBottom==0 ? '#fff' : '#f5f6f9' }" class="innerboxinput"> <view class="textareabox"> <textarea :style="{ background: '#f5f6f9' }" :showConfirmBar="false" @tap.stop="onFocus" :autoHeight="true" :adjustPosition="false" :maxlength="500" :focus="autoFocus" :hold-keyboard="true" @keyboardheightchange="onKeyBoardHeightChange" @blur="onBlur" @focus="onFocus" :height="inputHeight" v-model="commentText" :placeholder="placeholderText"></textarea> </view> <view v-show="offsetBottom != 0" class="send-btn" @tap.stop="sendComment" :class="{ 'send-active': commentText?.trim().length > 0 }"> 发送 </view> <view v-if="offsetBottom == 0" class="bottom-bar"> <view class="action-btn" @tap="toggleLike"> <image v-if="isLiked" src="./imgs/liked.png" style="width: 24px; height: 24px;margin-right: 5px;" mode=""></image> <image v-else src="./imgs/like.png" style="width: 24px; height: 24px;margin-right: 5px;" mode=""> </image> <text class="action-count">{{ details?.praiseNumber || 0 }}</text> </view> <view style="margin-left: 10px;" class="action-btn" @tap="toggleCollect"> <image v-if="isCollected" src="./imgs/collected.png" style="width: 24px; height: 24px;margin-right: 5px;" mode=""> </image> <image v-else src="./imgs/collect.png" style="width: 24px; height: 24px;margin-right: 5px;" mode=""> </image> <text class="action-count">{{ details?.hiddenNumber || 0 }}</text> </view> <view style="margin-left: 10px;" class="action-btn" @tap=""> <image src="/static/imgs/rf-appcomment.png" style="width: 24px; height: 24px;margin-right: 5px;" mode=""> </image> <text class="action-count">{{ details?.commentNumber || 0 }}</text> </view> </view> </view> </view>
const onKeyBoardHeightChange = (e) => { offsetBottom.value = e.detail.height > 0 ? e.detail.height : 0; };

使用@keyboardheightchange又会导致部分手机 输入框距离键盘过远

  1. 就用手动去改变softinputMode的值 ios等于adjustPan安卓等于adjustResize

这个是vue3的方法

import { getCurrentInstance, } from 'vue' const { proxy } = getCurrentInstance() const sys = uni.getSystemInfoSync(); const appWebview = proxy.$scope.$getAppWebview() console.log("appWebview",appWebview) appWebview.setStyle({ softinputMode: sys.platform=='ios'?'adjustPan':"adjustResize" });

vue2参考https://ask.dcloud.net.cn/question/113955

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/21 3:40:54

图像生成初探:OpenAI 与千帆平台一键出图

前面我们让 AI 学会了对话、推理&#xff0c;但一直局限于文字。今天我们要解锁一个新维度——图像生成。只需要一句描述&#xff0c;AI 就能帮你画出对应的图片。 在 Spring AI 中&#xff0c;图像生成和对话聊天使用的是完全不同的模型接口。对话用的是 ChatClient&#xff0…

作者头像 李华
网站建设 2026/5/21 3:39:57

别再傻等!EPLAN部件库导入太慢?试试这个解压导入法,效率翻倍

EPLAN部件库高效导入实战&#xff1a;解压法与便携式部署全解析 电气工程师们对EPLAN的部件库导入速度缓慢一定深有体会——当你拿到一个几百兆的EDZ文件&#xff0c;点击导入后泡杯咖啡回来可能进度条才走了一半。这种等待不仅浪费时间&#xff0c;更会打断工作节奏。本文将彻…

作者头像 李华
网站建设 2026/5/21 3:39:56

知网查重和AIGC检测有什么区别?2026论文AI率降到20%教程

“老师说我论文要过查重和查AI两关&#xff0c;这俩不是一回事吗&#xff1f;” 这是今年毕业季被问得最多的问题之一。很多同学以为查重和查AI是同一件事&#xff0c;或者以为过了查重就万事大吉。结果提交论文后被通知AI率超标&#xff0c;又得回来改。 今天把这两件事彻底讲…

作者头像 李华
网站建设 2026/5/21 3:37:04

cp520靶场学习笔记

正文1、端口扫描2、web登录页面用户密码爆破3、文件上传漏洞利用4、nc 反弹5、Linux用户检索与特权分析6、图片隐写7、解密与格式转换8、cp命令横向获取用户密码9、diff命令进行文件比较正文 kali攻击机地址&#xff1a;192.168.1.4 靶场地址&#xff1a;192.168.1.15 1、端口…

作者头像 李华
网站建设 2026/5/21 3:36:04

手把手教你用ProgISP和USBASP,给老旧Arduino开发板‘续命’升级Bootloader

用USBASP为老旧Arduino开发板重焕生机的完整指南 当你的Arduino开发板开始出现上传失败、响应迟缓或功能异常时&#xff0c;很可能是因为Bootloader固件老化或损坏。本文将详细介绍如何用成本不到20元的USBASP下载器和ProgISP软件&#xff0c;为基于ATmega328P的老款Arduino开发…

作者头像 李华