微信密码输入框功能效果实现(vue)

4 篇文章 0 订阅
1 篇文章 0 订阅

效果图如下:

html代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
    <link rel="stylesheet" type="text/css" href="./index.css">
    <title>密码验证</title>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div id="app" v-cloak>
    <div class="mypopup">
        <div class="content">
            <div class="close_btn" @click="closePop">X</div>
            <div class="main">
                <h3>请输入支付密码验证</h3>
                <p class="tip">密码错误,还可输入4次</p>
                <div class="pwipt">
                    <input type="password" @input="judgePassword" v-model="password" autofocus maxlength='6'>
                    <div class="border-right">
                        <span v-if="show1"></span>
                    </div>
                    <div class="border-right">
                        <span v-if="show2"></span>
                    </div>
                    <div class="border-right">
                        <span v-if="show3"></span>
                    </div>
                    <div class="border-right">
                        <span v-if="show4"></span>
                    </div>
                    <div class="border-right">
                        <span v-if="show5"></span>
                    </div>
                    <div>
                        <span v-if="show6"></span>
                    </div>
                </div>
                <div class="forgetpw">忘记密码?</div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.5.21/vue.js"></script>
<script type="text/javascript" src="./index.js"></script>
</html>

css代码:

* {
    margin: 0;
    padding: 0;
}
.mypopup {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: -webkit-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
}
.mypopup .content {
    position: relative;
    background: #fff;
    width: 75%;
    border-radius: 10px;
}
.mypopup .content .main {
    padding: 40px 30px;
    font-size: 12px;
    text-align: center;
}
.mypopup .content .main h3 {
    font-size: 18px;
    line-height: 2em;
    font-weight: 700;
}
.mypopup .content .main .tip {
    color: #EE4A4A;
    margin-bottom: 10px;
}
.mypopup .content .main .pwipt {
    font-size: 0;
    height: 45px;
    line-height: 45px;
    width: 220px;
    border: 1px solid #ccc;
}
.mypopup .content .main .pwipt div {
    display: inline-block;
    width: 16.2%;
    height: 45px;
    position: relative;
}
.mypopup .content .main .pwipt .border-right {
    border-right: 1px solid #ccc;
}
.mypopup .content .main .pwipt div>span {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #000;
    border-radius: 50%;
    left: 50%;
    top: 50%;
    margin-top: -5px;
    margin-left: -5px;
}
.mypopup .content .main .pwipt input {
    outline: none;
    border: 0;
    background: none;
    width: 900px;
    height: 0;
    padding: 22px 0;
    text-align: center;
    position: absolute;
    left: -500px;
    right: 0;
    z-index: 1000;
    color:transparent;
    text-indent: -999em;
}
.mypopup .content .close_btn {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 14px;
    height: 14px;
    z-index: 1000;
}
.forgetpw {
    font-size: 14px;
    color: #008AFF;
    margin-top: 10px;
    text-align: right;
}

js代码:

var vm = new Vue({
    el: '#app',
    data: {
        password: '',
        autofocus: true,
        show1: false,
        show2: false,
        show3: false,
        show4: false,
        show5: false,
        show6: false,
    },
    mounted: function () {

    },
    methods: {
        //关闭密码输入清空输入
        closePop: function() {
            this.password = '';
            this.judgePassword();
        },
        //校验密码
        surePassword: function() {
            // 调用密码校验接口

        },
        // 密码输入样式
        judgePassword: function() {
            if(this.password.length == 0) {
                this.show1 = false;this.show2 = false;this.show3 = false;this.show4 = false;this.show5 = false;this.show6 = false;
            }
            if(this.password.length == 1) {
                this.show1 = true;this.show2 = false;this.show3 = false;this.show4 = false;this.show5 = false;this.show6 = false;
            }
            if(this.password.length == 2) {
                this.show1 = true;this.show2 = true;this.show3 = false;this.show4 = false;this.show5 = false;this.show6 = false;
            }
            if(this.password.length == 3) {
                this.show1 = true;this.show2 = true;this.show3 = true;this.show4 = false;this.show5 = false;this.show6 = false;
            }
            if(this.password.length == 4) {
                this.show1 = true;this.show2 = true;this.show3 = true;this.show4 = true;this.show5 = false;this.show6 = false;
            }
            if(this.password.length == 5) {
                this.show1 = true;this.show2 = true;this.show3 = true;this.show4 = true;this.show5 = true;this.show6 = false;
            }
            if(this.password.length == 6) {
                this.show1 = true;this.show2 = true;this.show3 = true;this.show4 = true;this.show5 = true;this.show6 = true;
                // 接口校验密码
                this.surePassword();
            }
        },
    }
});

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值