收藏
回答

textarea上推页面使标题消失?

使用自定义头固定定位标题栏也会上推,阻止上推的话,键盘不会自动弹起,输入框被键盘遮挡,试过使用scroll-into-view属性,输入框聚焦时定位到下一个,不起效果,有没有哪个大佬给点思路,谢谢 以下是代码片段 https://developers.weixin.qq.com/s/B1R6zqm27nC8

最后一次编辑于  2022-09-21
回答关注问题邀请回答
收藏

1 个回答

  • ______
    ______
    2022-09-21

    大概思路:使用position: fixed,给textarea绑定bindkeyboardheightchange事件,当键盘高度变化时更新position: fixed元素的top值。

    <view class="fixed" style="top: {{fixedTop}}px">fixed on the top</view>
    ...
    
    <textarea placeholder="请填写" bindkeyboardheightchange="onKeyboardHeightChange"></textarea>
    


    .fixed {
      position: fixed;
      top: 0;
      right: 0;
      left: 0;
    }
    


    Page({
    data: {
      fixedTop: 0
    },
    onKeyboardHeightChange(e) {
      this.setData({
        fixedTop: e.detail.height > 0 ? e.detail.height : 0
      })
    }
    })
    
    2022-09-21
    有用
    回复 3
    • 子游
      子游
      2022-09-22
      没有看明白呢,标题固定定位么?键盘高度可以通过focus事件获取到
      2022-09-22
      回复
    • ______
      ______
      2022-09-22回复子游
      对,就是软键盘弹起以后,更改固定位置。
      2022-09-22
      回复
    • 子游
      子游
      2022-09-22回复______
      这个最开始就试过了,因为是整个页面都上推了 还有局部滚动,数值算不准,所以就放弃了
      2022-09-22
      回复
登录 后发表内容