learning-note icon indicating copy to clipboard operation
learning-note copied to clipboard

用vue模拟支付密码框

Open jackPanyj opened this issue 8 years ago • 0 comments

在手机端经常见到那种让输入密码的,比如手机支付的时候输入的支付密码, 相信这样的效果应该很常见,如何用web技术模拟一个呢?

我用vue简单的写了一个demo

先展示效果图:

html 代码:

    <div class="container">
        <div class="item" v-for="i in 4">{{numbers[i-1]}}</div>
        <input v-model="numbers" maxlength="4" type="tel" autofocus="autofocus"/>
    </div>

css 代码:

body {
  display: flex;
  height: 100vh;
}

.container {
  position: relative;
  margin: auto;
  height: 80px;
  width: 300px;
  display: flex;
  border: 1px solid blue;
}

.item {
  flex-basis: 25%;
  font-size: 40px;
  text-align: center;
  line-height: 80px;
}
.item:not(:last-of-type) {
  border-right: 1px solid blue;
}

input {
  position: absolute;
  height: 80px;
  opacity: 0;
  left: 0;
  width: 300px;
}

js 代码:

new Vue({
	el: '.container',
	data: {
		numbers: ''
	}
})

解释下思路,其实就是一个输入框,浮在上面透明展示,然后下面是四个div,用来展示数字的。

demo链接

jackPanyj avatar Feb 10 '17 09:02 jackPanyj