uni-app 元素使用fixed定位无法遮挡uni-easyinput增强输入框的光标

uni-app 元素使用fixed定位无法遮挡uni-easyinput增强输入框的光标

项目属性 信息
产品分类 uniapp/App
PC开发环境操作系统 Mac
PC开发环境操作系统版本号 14.2.1 (23C71)
HBuilderX类型 正式
HBuilderX版本号 3.99
手机系统 iOS
手机系统版本号 iOS 17
手机厂商 苹果
手机机型 iphone14pro
页面类型 vue
vue版本 vue2
打包方式 云端
项目创建方式 HBuilderX

操作步骤:

页面内容超出一屏时,按钮元素使用fixed定位到底部且z-index为999,uni-easyinput 增强输入框获取焦点后,显示光标;上下滑动屏幕滚动时,按钮元素无法遮挡uni-easyinput 增强输入框的光标

预期结果:

元素使用fixed定位 可以遮挡uni-easyinput 增强输入框的光标

实际结果:

元素使用fixed定位且z-index为999,无法遮挡uni-easyinput 增强输入框的光标

bug描述:

元素使用fixed定位且z-index为999,无法遮挡uni-easyinput 增强输入框的光标

Image 1 Image 2


更多关于uni-app 元素使用fixed定位无法遮挡uni-easyinput增强输入框的光标的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

已复现该问题,此为IOSinput框光标特有问题,无法被任何元素覆盖,建议在被遮挡时,将input框隐藏或者设置margin-left: -100%; text-indent: -999em;来使光标错位或者在滑动时取消输入框的聚焦。 以下为使光标错位的示例代码: <template>
<view>
<view class="container">
<view class="fixed">
遮罩层
</view>
<input type="text" class="input" style="height: 100%;background-color: blue;" v-model="text" />
</view>
</view>
</template>

<script> export default { data() { return { text: "", } }, } </script> <style lang="scss"> .container { height: 18px; } .input { margin-left: -100%; text-indent: -999em; } .fixed { position: fixed; background-color: red; color: white; } </style>

更多关于uni-app 元素使用fixed定位无法遮挡uni-easyinput增强输入框的光标的实战教程也可以访问 https://www.itying.com/category-93-b0.html


uni-app 中使用 fixed 定位的元素无法遮挡 uni-easyinput 增强输入框的光标,这通常是由于 z-index 的层级问题导致的。uni-easyinput 组件的光标可能具有较高的 z-index 值,导致即使你使用了 fixed 定位的元素也无法遮挡它。

解决方案

  1. 调整 z-index
    确保你的 fixed 定位元素的 z-index 值高于 uni-easyinput 组件的光标的 z-index 值。你可以尝试为 fixed 元素设置一个较高的 z-index 值,例如:

    .fixed-element {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 9999; /* 确保这个值足够高 */
    }
    
  2. 检查 uni-easyinputz-index
    如果 uni-easyinput 组件本身或其光标具有较高的 z-index,你可能需要找到并调整它的 z-index 值。你可以通过浏览器的开发者工具检查 uni-easyinput 的样式,找到其 z-index 值,并确保你的 fixed 元素的 z-index 高于它。

  3. 使用 cover-view 组件
    uni-app 中,cover-view 组件可以用于覆盖原生组件(如输入框、视频等)。你可以尝试使用 cover-view 来代替普通的 view 元素:

    <cover-view class="fixed-element"></cover-view>
    
    .fixed-element {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 9999;
    }
    
  4. 动态控制输入框的显示
    如果你希望在某些情况下隐藏输入框的光标,可以通过动态控制 uni-easyinput 的显示与隐藏来实现:

    <uni-easyinput v-if="showInput" placeholder="请输入内容"></uni-easyinput>
    
    export default {
        data() {
            return {
                showInput: true
            };
        },
        methods: {
            hideInput() {
                this.showInput = false;
            },
            showInput() {
                this.showInput = true;
            }
        }
    };
回到顶部