小程序中textarea层级问题

小程序开发中,有些原生组件,比如textarea存在层级太高的问题,一般发生在两种场景:

1.页面较长,然后底部有固定fixed的按钮
2.页面有自定义弹窗时

这两种情况下,textarea中的文字都会穿透固定按钮和弹窗浮在最上层。找了很多方法,可能最合适的就是自定义一个替代元素,以下附上完整的代码(wepy框架小程序):

template中的html:

    <view class="demo">

      <textarea class="weui-textarea" maxlength='150' auto-focus="isFocus" @blur="bindContentBlur" value='{{mediaDemo}}' @input="bindTextAreaBlur" wx:if="{{isInputContentFocus}}" placeholder="请输入媒体详情" placeholder-class="phClass"></textarea>

    <!-- 下面是替代元素 -->

      <scroll-view scroll-y class="content" @tap="bindContentFocus" wx:if="{{isContentFocus}}">

        <div class="placeholder" wx:if="{{!mediaDemo}}">请输入媒体详情</div>

        <div style="word-wrap:break-word;word-break:break-all;" wx:else>{{mediaDemo}}</div>

      </scroll-view>

    </view>
 

data中涉及到的变量:

data={

      mediaDemo: '',

      isContentFocus: true,

      isInputContentFocus: false,

      isFocus: false,

}

methods中的方法:

  methods = {

      bindTextAreaBlur(e) {

        this.mediaDemo = e.detail.value;

        this.$apply();

      },

      bindContentFocus() {

        this.isFocus = true;

        this.isContentFocus = false;

        this.isInputContentFocus = true;

        this.$apply();

      },

      bindContentBlur() {

        this.isContentFocus = true;

        this.isInputContentFocus = false;

        this.isFocus = false;

        this.$apply();

      }

    };

style中的样式:

  .weui-textarea {

    border: 1px solid #afb8cd;

    background: #fff;

    padding: 20rpx;

    border-radius: 5rpx;

    height: 150rpx;

    margin: 30rpx auto 100rpx auto;

    width: 86%;

  }

 

  .content {

    margin: 30rpx auto 100rpx auto;

    border: 1px solid #afb8cd;

    background: #fff;

    padding: 15rpx 20rpx 26rpx 20rpx;

    border-radius: 5rpx;

    height: 150rpx;

    width: 86%;

  }

 

  .phClass,

  .placeholder {

    color: #999;

  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值