根据ui设计稿,css
原本思路是一个input搞定,下面的线使用背景图git
background:url('/images/line.png')no-repeat bottom center;github
而后使用letter-spacing,让字体间隔开。小程序
可是遇到了小程序的坑,letter-sapcing在input中没效果。数组
因而我gitlab上找到一个,模拟光标输入框的源码,并借鉴了做者的思路。(连接以下:https://github.com/evan2020/six-Input-box)gitlab
因而个人新思路是这样的:字体
仍然使用一个input,并设置auto-focus,这样当进入页面的时候,手机端会自动弹出数字键盘。动画
而后模拟光标的css以下:ui
.cursor { width: 1px; height:80rpx; background-color: #2AC3A4; animation: focus 0.7s infinite; } /* 光标动画 */ @keyframes focus { from { opacity: 1; } to { opacity: 0; } }
1)input设置margin-left:-100%,不显示在页面可视区域中,url
2)上面线框位置,使用view标签,仍然使用背景图展现下面的间断线
3)使用bindinput监听input值的变化,并经过numList = [...e.detail.value]将input的值(字符串)转换为数组。并渲染在view中
<view id="searchNum" class="set-number" style="background:url({{line}}) no-repeat bottom center;background-size:100%"> <view class="set-number-content"> <view wx:if="{{!numList.length}}" class="cursor"></view> <text wx:if="{{numList.length}}">{{numList[0]}}</text> </view> <view class="set-number-content"> <view wx:if="{{numList.length===1}}" class="cursor"></view> <text wx:if="{{numList.length>=2}}">{{numList[1]}}</text> </view> <view class="set-number-content"> <view wx:if="{{numList.length===2}}" class="cursor"></view> <text wx:if="{{numList.length>=3}}">{{numList[2]}}</text> </view> <view class="set-number-content"> <view wx:if="{{numList.length===3}}" class="cursor"></view> <text wx:if="{{numList.length>=4}}">{{numList[3]}}</text> </view> </view>
你们有更好的思路的,欢迎来赐教