8

微信小程序键盘遮挡解决方案

 1 year ago
source link: https://www.iplayio.cn/post/032185690
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

微信小程序键盘遮挡解决方案

发布:1天前 更新:1天前 folder_open 第三方平台对接 微信 15 浏览 comment

原文地址:微信小程序键盘遮挡解决方案

微信小程序键盘遮挡解决方案,非常简单的实现方法。

<popup style="{ {changeFixedBottom}}">
<textarea
                            auto-focus="{ {true}}"
                            bindblur="textBlur"
                            bindfocus="textFocus"
                            adjust-position="{ {false}}"
                            show-confirm-bar="{ {false}}"
                            bindinput="nicknameInput" class="{ {['input']}}"
                            value="{ {patchData.nickname}}"
                            maxlength="{ {9}}"></textarea>
</popup>

adjust-position:虚拟键盘抬起,页面是否向上推动。

show-confirm-bar:是否显示完成按钮

bindfocus:输入框出于焦点时

bindblur:输入框失去焦点

说明:popup是你使用的组件,当调起popup时候,输入框处于焦点状态,虚拟键盘调起。这个时候需要把popup的组件的bottom值改为键盘高度,也就是changeFixedBottom变为键盘高度。当输入框失去焦点的时候,把popup组件的bottom值改为0。js代码如下:

Page({
data:{
  changeFixedBottom:"bottom:0",
},
textBlur(e) {
        //testData.store("textBlur bottom:"+e.detail.height+'px')
        this.setData({
            changeFixedBottom: "bottom:0"
        })
    },
    textFocus(e) {
        //testData.store("textFocus bottom:"+e.detail.height+'px')
        this.setData({
            changeFixedBottom: "bottom:" + e.detail.height + 'px'
        })
    },

})

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK