Vue 实现6位数密码(iOS WebView卡顿优化)

ios系统,原生 webview 嵌套H5页面使用时,编写完成的6位数输入密码,输入密码卡顿问题的解决方案:

如下图:

6位数密码图

原因是因为,CSS 这块 造成的。简单来说,style left 为负数的时候出现的,android 目测不会出现此问题

input[type=tel] {
    opacity: 0;
    z-index: -1;
    position: absolute;
    left:-100%;
}
解决方案:

重新设置 input样式问题

input[type=tel] {
    width: 0.1px;
    height: 0.1px;
    color: transparent;
    position: relative;
    top: 23px;
    background: #000000;
    left: 46px;
    border: none;
    font-size: 18px;
    opacity: 0;
    z-index: -1;
}

——————— 全部代码在这,你可以拿出去使用即可 ———————-

<template>
    <div id="payPwd">
        <header>支付密码设置</header>
        <input ref="pwd" type="tel" maxlength="6" v-model="msg" class="pwd" unselectable="on" />
        <ul class="pwd-wrap" @click="focus">
            <li :class="msg.length == 0?'psd-blink':''"><i v-if="msg.length > 0"></i></li>
            <li :class="msg.length == 1?'psd-blink':''"><i v-if="msg.length > 1"></i></li>
            <li :class="msg.length == 2?'psd-blink':''"><i v-if="msg.length > 2"></i></li>
            <li :class="msg.length == 3?'psd-blink':''"><i v-if="msg.length > 3"></i></li>
            <li :class="msg.length == 4?'psd-blink':''"><i v-if="msg.length > 4"></i></li>
            <li :class="msg.length == 5?'psd-blink':''"><i v-if="msg.length > 5"></i></li>
        </ul>
        <button type="button" @click="sendCode">获取验证码 lodding</button>
    </div>
</template>
<script>
    import api from "./api";
    import "@/js/utils"; //公共方法
    export default {
        components: {},
        data() {
            return {
                msg: '',
            }
        },
        created() {},
        computed: {},
        watch: {
            msg(curVal) {
                if(/[^\d]/g.test(curVal)) {
                    this.msg = this.msg.replace(/[^\d]/g, '');
                }
            },
        },
        methods: {
            focus() {
                this.$refs.pwd.focus();
            },
            sendCode() {
                //时间
                utils.sendCode(event.target);

                //showLoading
                utils.view.showLoading();

                setTimeout(function() {
                    utils.view.dismissLoading();
                }, 5000);
            }
        },
        mounted() {}
    }
</script>
<style lang="less" scoped>
    #payPwd {
        height: auto;
        header {
            text-align: center;
            height: 80px;
            line-height: 90px;
            text-align: center;
        }
        input[type=tel] {
            width: 0.1px;
            height: 0.1px;
            color: transparent;
            position: relative;
            top: 23px;
            background: #000000;
            left: 46px;
            border: none;
            font-size: 18px;
            opacity: 0;
            z-index: -1;
        }
        //光标
        .psd-blink {
            display: inline-block;
            background: url("./img/blink.gif") no-repeat center;
        }
        .pwd-wrap {
            width: 90%;
            height: 50px;
            padding-bottom: 1px;
            margin: 0 auto;
            background: #fff;
            border: 1px solid #ddd;
            display: flex;
            display: -webkit-box;
            display: -webkit-flex;
            cursor: pointer;
            position: absolute;
            left: 0;
            right: 0;
            top: 13%;
            z-index: 10;
            li {
                list-style-type: none;
                text-align: center;
                line-height: 50px;
                -webkit-box-flex: 1;
                flex: 1;
                -webkit-flex: 1;
                border-right: 1px solid #ddd;
                &:last-child {
                    border-right: 0;
                }
                i {
                    height: 10px;
                    width: 10px;
                    border-radius: 50%;
                    background: #000;
                    display: inline-block;
                }
            }
        }
        button {
            position: relative;
            display: block;
            height: 41px;
            text-align: center;
            margin: 0 auto;
            margin-top: 70%;
            padding: 0 20px;
            border-radius: 5px;
            font-size: 16px;
            border: 1px solid #dddddd;
            background: #dddddd;
            color: #000000;
        }
    }
</style>

附加:如果不想使用光标,直接

//去掉 :class="msg.length == 0?'psd-blink':''" 即可
<li><i v-if="msg.length > 0"></i></li>

gitHub:在这里

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Rkatsiteli

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

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

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

打赏作者

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

抵扣说明:

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

余额充值