jQuery仿移動(dòng)端支付寶鍵盤(pán)的實(shí)現(xiàn)代碼
最近做項(xiàng)目時(shí)碰到一個(gè)需求,就是在移動(dòng)端支付頁(yè)面點(diǎn)擊支付按鈕彈出一個(gè)支付鍵盤(pán),類似于支付寶的那種。由于項(xiàng)目只是單純的手機(jī)網(wǎng)站,而并非app,所以這個(gè)功能得由前端來(lái)實(shí)現(xiàn)。話不多說(shuō),先上圖看看效果。

這不就是支付寶app那個(gè)支付鍵盤(pán)嗎? 沒(méi)錯(cuò),咱們UI就是參照支付寶做的這個(gè)鍵盤(pán)。你可能會(huì)問(wèn),為什么不直接調(diào)用支付寶提供的支付接口呢。額,因?yàn)轫?xiàng)目需要,這里就不多解釋了。
我們先看一下實(shí)現(xiàn)后的效果圖



HTML部分
<!-- 支付鍵盤(pán) -->
<divclass="pay-container">
<divclass="pay-title">
<spanclass="pay-title-remove">×</span>
輸入支付密碼
</div>
<divclass="pay-body">
<divclass="input-container">
<inputclass="input-item"type="password"readonly>
<inputclass="input-item"type="password"readonly>
<inputclass="input-item"type="password"readonly>
<inputclass="input-item"type="password"readonly>
<inputclass="input-item"type="password"readonly>
<inputclass="input-item"type="password"readonly>
</div>
<divclass="forgetPwd-container">
<aclass="forgetPwd"href="">忘記密碼?</a>
</div>
<divclass="key-container">
<divclass="key-item">1</div>
<divclass="key-item">2</div>
<divclass="key-item">3</div>
<divclass="key-item">4</div>
<divclass="key-item">5</div>
<divclass="key-item">6</div>
<divclass="key-item">7</div>
<divclass="key-item">8</div>
<divclass="key-item">9</div>
<divclass="key-item empty"></div>
<divclass="key-item">0</div>
<divclass="key-item remove"></div>
</div>
</div>
</div>CSS部分
.pay-container{ width:7.5rem; height:8rem; background-color:#fbf9fb; position:fixed;z-index:999; overflow:hidden;display:none; }
/* .pay-container-show{transform: translate3d(0, -8.9rem, 0);transition: 0.5s ease;transform: translate3d(0, 0, 0); transition: 0.5s ease;} */
.pay-title{ height:0.96rem; line-height:0.96rem; border-bottom:1pxsolid#b3afaf; text-align:center; color:#070707;
position:relative; font-size:0.36rem;}
.pay-title.pay-title-remove{ width:0.24rem; height:0.24rem; position:absolute; top:0.35rem; left:0.33rem; line-height:0.28rem;
font-size:0.45rem;}
.pay-body{ padding-top:0.56rem;position:relative; height:7rem; box-sizing:border-box;}
.pay-body.input-container{ width:6.74rem; height:0.93rem; border:1pxsolid#ebe8eb; overflow:hidden; border-radius:5px;
background-color:#fff; margin:0auto; display:flex;flex-direction:row;align-items:center;
flex-wrap:wrap; justify-content:center;align-content:center;}
.pay-body.input-container.input-item{ width:1.1rem; height:0.92rem; display:inline-block; margin:0; border-right:1pxsolid#ebe8eb;
text-align:center; line-height:0.92rem; border-radius:0; }
.pay-body.input-container.input-item:nth-last-child(1){ border-right:0;}
.pay-body.forgetPwd-container{width:6.74rem;margin:0.22remauto0; text-align:right;}
.pay-body.forgetPwd-container.forgetPwd{ color:#52bfff; font-size:0.24rem; }
.pay-body.key-container{ width:100%; height:4.56rem; position:absolute; bottom:0; display:flex;flex-direction:row;align-items:center;
flex-wrap:wrap; justify-content:center;align-content:center; }
.pay-body.key-container.key-item{ width:2.47rem; height:1.12rem; line-height:1.12rem; text-align:center; border-right:2pxsolid#f3f3f3;
border-top:2pxsolid#f3f3f3; font-size:0.66rem; color:#1e1d1f;background-color:#fff;}
.pay-body.key-container.key-item:nth-child(3),
.pay-body.key-container.key-item:nth-child(6),
.pay-body.key-container.key-item:nth-child(9),
.pay-body.key-container.key-item:nth-child(12){ border-right:0;}
.pay-body.key-container.key-item.remove,.pay-body.key-container.key-item.empty{ font-size:0.24rem;background-color:#e6e9f1;}
.pay-body.key-container.key-item.remove{ background:url('../images/pay-remove.png') centerno-repeat#e6e9f1; background-size:.52rem.32rem; }
.pay-body.key-container.selected{ background-color:#e4e8f4;}核心JS部分
var arr = [];
var num =0;
//響應(yīng)鍵盤(pán)事件
$('.key-item').on('touchstart', function () {
$(this).addClass('selected')
})
$('.key-item').on('touchend', function () {
$(this).removeClass('selected')
})
$('.key-item').on('click', function () {
var value =$(this).text();
var inputItem =$('.layui-m-layercont .input-item');
if (!$(this).hasClass('remove')) {
if (num <6) {
$(inputItem[num]).val(value);
if (num ==5) {
var arr = [];
for (var i =0; i < inputItem.length; i++) {
arr.push(inputItem[i].value)
}
arr =parseInt(arr.join(''));
if (arr !==123456) {
layer.open({
content:'支付密碼錯(cuò)誤請(qǐng)重新輸入!',
skin:'msg',
time:2//2秒后自動(dòng)關(guān)閉
});
} else {
layer.open({
content:'輸入正確!',
skin:'msg',
time:2//2秒后自動(dòng)關(guān)閉
});
}
num++;
returnfalse;
}
num++;
}
} else {
if (num >0) {
num--;
$(inputItem[num]).val('');
}
}
})總結(jié)
以上所述是小編給大家介紹的jQuery仿移動(dòng)端支付寶鍵盤(pán)的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- jquery 鍵盤(pán)事件的使用方法詳解
- jQuery實(shí)現(xiàn)鍵盤(pán)回車搜索功能
- jQuery實(shí)現(xiàn)手機(jī)上輸入后隱藏鍵盤(pán)功能
- js監(jiān)聽(tīng)鍵盤(pán)事件的方法_原生和jquery的區(qū)別詳解
- jquery中鍵盤(pán)事件小結(jié)
- jQuery簡(jiǎn)單獲取鍵盤(pán)事件的方法
- jQuery禁用鍵盤(pán)后退屏蔽F5刷新及禁用右鍵單擊
- js和jquery實(shí)現(xiàn)監(jiān)聽(tīng)鍵盤(pán)事件示例代碼
- jquery比較簡(jiǎn)潔的軟鍵盤(pán)特效實(shí)現(xiàn)方法
- 打造個(gè)性化的功能強(qiáng)大的Jquery虛擬鍵盤(pán)(VirtualKeyboard)
相關(guān)文章
jQuery實(shí)現(xiàn)每日秒殺商品倒計(jì)時(shí)功能
這篇文章主要介紹了 jQuery實(shí)現(xiàn)每日秒殺商品倒計(jì)時(shí)功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09
jQuery中的ready函數(shù)與window.onload誰(shuí)先執(zhí)行
這篇文章主要介紹了jquery中ready函數(shù)與window.onload函數(shù)的區(qū)別,別講解了他們各自執(zhí)行的時(shí)機(jī),通俗易懂,需要的朋友可以參考下。2016-06-06
jQuery圖片預(yù)加載 等比縮放實(shí)現(xiàn)代碼
jQuery圖片預(yù)加載 等比縮放實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-10-10
解決jquery操作checkbox火狐下第二次無(wú)法勾選問(wèn)題
在工作中使用jquery操作checkbox,進(jìn)行全選、反選,現(xiàn)在的問(wèn)題是火狐下第二次無(wú)法勾選問(wèn)題,在下面有個(gè)詳細(xì)的解答,感興趣的朋友可以參考下2014-02-02
jQuery操作Select的Option上下移動(dòng)及移除添加等等
jQuery操作Select Option:向上移動(dòng)選中的option、向下移動(dòng)選中的option、移除選中的option、獲取所有的option值、添加option等等,下面有個(gè)不錯(cuò)的示例,感興趣的朋友不要錯(cuò)過(guò)2013-11-11
jQuery得到多個(gè)值只能用取Class ,不能用取ID的方法
下面小編就為大家?guī)?lái)一篇jQuery得到多個(gè)值只能用取Class ,不能用取ID的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-12-12
使用JQuery快速實(shí)現(xiàn)Tab的AJAX動(dòng)態(tài)載入(實(shí)例講解)
這篇文章主要介紹了使用JQuery快速實(shí)現(xiàn)Tab的AJAX動(dòng)態(tài)載入(實(shí)例講解)需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12

