微信小程序做登录密码显示隐藏效果 并解决安卓手机端隐藏密码时小黑点显示过大问题

 在编辑器和苹果手机上面显示就是正常的大小,在安卓手机上面黑点就非常大,需要单独调

 

安卓手机显示比较大

 wxml

注意:在html中的input是通过切换type的属性值来实现隐藏显示的

在微信小程序的input里面type没有password属性 是通过password属性的true或者false来设置是否为密码框

<view class="input-item">
        <text class="tit">密码</text>
        <view style="display: flex;justify-content: space-between; width: 100%;">
          <input style="font-size: {{size}};" type="text" bindinput="input" password="{{show}}" placeholder="请输入密码" model:value="{{password}}" />
          <van-icon style="padding:0 30rpx;" bindtap="showpassword" name="{{show?'eye-o':'closed-eye'}}" color="#000000" />
        </view>
      </view>

 wxss

.input-item{
  display:flex;
  flex-direction: column;
  align-items:flex-start;
  justify-content: center;
  padding: 0 30rpx;
  background:#dddddde1;
  height: 120rpx;
  border-radius: 4px;
  margin-bottom: 50rpx;

}

.input-item:last-child{
  margin-bottom: 0;
}
.input-item .tit{
  height: 50rpx;
  line-height: 56rpx;
  font-size: 30rpx;
  color: #606266;
}
.input-item input{
  height: 60rpx;
  font-size: 30rpx;
  color: #303133;
  width: 100%;
}

js

data: {
    // 显示隐藏密码
    let size = this.data.size,
    let show = this.data.show,
    let isandroid = this.data.isandroid,
    // 密码
    password: "",
  },


   onShow() {
    let size = this.data.size
    let show = this.data.show
    let isandroid = this.data.isandroid
    // 获取手机类型 安卓、苹果
    wx.getSystemInfo({
      success(res) {
        // console.log(res.platform)
        if (res.platform == "android" && show) {
          size = "20rpx"
          isandroid = true
        }
      }
    })
    this.setData({
      size: size,
      isandroid: isandroid
    })
  },

   // 切换显示密码
  showpassword() {
    // 安卓手机在有内容并且是从显示状态到隐藏状态就变为小字体 其他情况都为正常大字体
    if (this.data.isandroid && !this.data.show && this.data.password) {
      // 安卓手机
      this.setData({
        show: !this.data.show,
        size: "20rpx"
      })
    } else {
      // 其他手机
      this.setData({
        show: !this.data.show,
        size: "30rpx"
      })
    }
  },
  // 密码输入中
  input() {
    // 在输入中如果是安卓手机并且有内容并且当前显示状态为隐藏就变成小字体 其他情况都为正常大字体
    if (this.data.isandroid && this.data.password && this.data.show) {
      this.setData({
        size: "20rpx"
      })
    } else {
      this.setData({
        size: "30rpx"
      })
    }
  },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

巨蟹座守护骑士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值