angular仿支付宝密码框输入效果
发布时间 - 2026-01-11 00:21:24 点击率:次项目需求,使用ng写一个密码框格子支付模块,一开始使用一个input+letter-spacing来分割字符,但是发现间距非常不好控制,随着字符的输入文本框字符串间距还会自动调整。最终从网上查找到一款jq仿支付宝密码输入框,于是我模仿编写了个指令模块。

效果如下:
完整代码如下:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="format-detection" content="telephone=no"/>
<title>使用ng仿写支付宝密码框</title>
<style>
*{ margin: 0; padding: 0;}
.t{ margin-left: 100px;}
.pass-form{position:relative;top:20px; left: 50px; width:100%;}
.pass-form .pass-input{position:absolute;top:0;height:75px;line-height:75px;font-size:14px;color:#000;opacity:0;box-shadow:none}
.pass-form .pass-border-box{position:absolute;top:0;font-size:0}
.pass-form .pass-border-box .faguang{position:absolute;top:0;left:0;z-index:9;box-shadow:0 0 8px rgba(60,100,100,.6);width:75px;height:75px;background:#fff;opacity:0}
.pass-form .pass-border-box .pass-border{display:inline-block;position:relative;z-index:10;width:75px;height:75px;border:solid 1px #dcdcdc;border-left:none;-webkit-box-sizing:border-box;box-sizing:border-box}
.pass-form .pass-border-box .pass-border:first-child{border-left:solid 1px #dcdcdc}
.pass-form .pass-border-box .pass-border.active{background:url(../img/icons/icon_guangbiao.gif) no-repeat center center #fff}
.pass-form .pass-border-box .pass-border i{display:block;margin:0 auto;margin-top:22px;width:20px;height:20px;border-radius:100%}
</style>
</head>
<body ng-app="demo" ng-controller="pageCtrl">
<div class="t">ng仿写支付宝密码框</div>
<form class="pass-form" name="pass_form" novalidate pass-form>
<label for="pass">
<input class="pass-input Jpass" type="tel" name="pass" id="pass" autocomplete="off" ng-model="pass" required maxlength="6" />
<div class="pass-border-box">
<span class="pass-border"><i>dot</i></span>
<span class="pass-border"><i>dot</i></span>
<span class="pass-border"><i>dot</i></span>
<span class="pass-border"><i>dot</i></span>
<span class="pass-border"><i>dot</i></span>
<span class="pass-border"><i>dot</i></span>
<div class="faguang Jfaguang"></div>
</div>
</label>
</form>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script>
var app=angular.module('demo', []);
app.controller('pageCtrl', function($scope, $interval, $http, $q){
$scope.pass='';
// $interval(function(){
// console.log('定时检查:'+$scope.pass);
// }, 5000);
})
.directive('passForm', function($http){
return {
restrict: 'EA',
link: function(scope, ele, attr){
var inputDom=angular.element(ele[0].querySelector('.Jpass'));//密码框
var spanDoms=ele.find('span');//光标span
var faguang=angular.element(ele[0].querySelector('.Jfaguang'));//发光外框
var that=this;
inputDom.on('focus blur keyup', function(e){
e=e? e : window.event;
e.stopPropagation();
console.log('value len:'+this.value.length);
console.log(e.type);
if(e.type==='focus'){
var _currFocusInputLen=this.value.length===6? 5 : this.value.length;
spanDoms.eq(_currFocusInputLen).addClass('active');
faguang.css({left: _currFocusInputLen * 75+'px', opacity: 1});
}else if(e.type==='blur'){
var _currBlurInputLen = this.value.length;
spanDoms.eq(_currBlurInputLen).removeClass('active');
faguang.css({opacity: 0});
}else if(e.type==='keyup'){
//console.log(this.value);
//键盘上的数字键按下才可以输入
if(e.keyCode == 8 || (e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105)){
var curInputLen = this.value.length;//输入的文本内容长度
for (var j = 0; j < 6; j++) {
spanDoms.eq(j).removeClass('active');
spanDoms.eq(curInputLen).addClass('active');
spanDoms.eq(curInputLen - 1).next().find('i').css({backgroundColor: 'transparent'});
spanDoms.eq(curInputLen - 1).find('i').css({backgroundColor: '#000'});
faguang.css({
left: curInputLen * 75 + 'px'
});
}
if (curInputLen === 0) {
spanDoms.find('i').css({backgroundColor: 'transparent'});
}
if (curInputLen === 6) {
spanDoms.eq(5).addClass('active');
faguang.css({
left: '375px'
});
//直接发起密码验证
var doSubmitCallback=function(){
scope.pass='';
spanDoms.find('i').css({backgroundColor: 'transparent'});
spanDoms.removeClass('active').eq(0).addClass('active');
faguang.css({
left: '0'
});
};
// $http.get('http://xxxx/test.php?pass='+this.value)
// .success(function(res){
// console.log(res);
// if(res.status){
// doSubmitCallback();
// console.log(that.value+'-----');
// }else{
// doSubmitCallback();
// }
// });
}
}else{
this.value = this.value.replace(/\D/g,'');
}
}
});
}
}
});
</script>
</body>
</html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# angular仿支付宝密码框
# js仿支付宝密码输入框
# angularjs2 ng2 密码隐藏显示的实例代码
# Angularjs修改密码的实例代码
# AngularJS前端页面操作之用户修改密码功能示例
# 在 Angular2 中实现自定义校验指令(确认密码)的方法
# AngularJs验证重复密码的方法(两种)
# angularjs 表单密码验证自定义指令实现代码
# Angular实现点击按钮控制隐藏和显示功能示例
# Angular实现点击按钮后在上方显示输入内容的方法
# AngularJS实现根据不同条件显示不同控件
# AngularJS实时获取并显示密码的方法
# 支付宝
# 仿写
# 还会
# 才可以
# 写了
# 按下
# 大家多多
# 文本框
# 输入框
# 数字键
# 网上
# font
# shadow
# border
# size
# color
# box
# opacity
# relative
# top
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
JS中对数组元素进行增删改移的方法总结
网站制作怎么样才能赚钱,用自己的电脑做服务器架设网站有什么利弊,能赚钱吗?
Laravel如何实现URL美化Slug功能_Laravel使用eloquent-sluggable生成别名【方法】
青岛网站建设如何选择本地服务器?
如何在Windows环境下新建FTP站点并设置权限?
详解vue.js组件化开发实践
如何快速打造个性化非模板自助建站?
如何做网站制作流程,*游戏网站怎么搭建?
Win11怎样安装网易有道词典_Win11安装词典教程【步骤】
Laravel如何使用模型观察者?(Observer代码示例)
厦门模型网站设计制作公司,厦门航空飞机模型掉色怎么办?
Bootstrap整体框架之CSS12栅格系统
Laravel如何处理CORS跨域问题_Laravel项目CORS配置与解决方案
百度浏览器网页无法复制文字怎么办 百度浏览器复制修复
标题:Vue + Vuex 项目中正确使用 JWT 进行身份认证的实践指南
如何用AI帮你把自己的生活经历写成一个有趣的故事?
Swift中swift中的switch 语句
昵图网官方站入口 昵图网素材图库官网入口
Laravel怎么创建自己的包(Package)_Laravel扩展包开发入门到发布
iOS中将个别页面强制横屏其他页面竖屏
Laravel如何实现多级无限分类_Laravel递归模型关联与树状数据输出【方法】
laravel服务容器和依赖注入怎么理解_laravel服务容器与依赖注入解析
高防网站服务器:DDoS防御与BGP线路的AI智能防护方案
如何快速上传建站程序避免常见错误?
香港服务器建站指南:免备案优势与SEO优化技巧全解析
Win10如何卸载预装Edge扩展_Win10卸载Edge扩展教程【方法】
浅述节点的创建及常见功能的实现
如何快速选择适合个人网站的云服务器配置?
如何将凡科建站内容保存为本地文件?
常州企业网站制作公司,全国继续教育网怎么登录?
千问怎样用提示词获取健康建议_千问健康类提示词注意事项【指南】
如何在Windows虚拟主机上快速搭建网站?
如何快速搭建FTP站点实现文件共享?
javascript如何操作浏览器历史记录_怎样实现无刷新导航
如何续费美橙建站之星域名及服务?
微信小程序 require机制详解及实例代码
Laravel如何编写单元测试和功能测试?(PHPUnit示例)
黑客如何通过漏洞一步步攻陷网站服务器?
*服务器网站为何频现安全漏洞?
EditPlus中的正则表达式 实战(1)
javascript和jQuery中的AJAX技术详解【包含AJAX各种跨域技术】
Laravel怎么集成Vue.js_Laravel Mix配置Vue开发环境
如何获取PHP WAP自助建站系统源码?
laravel怎么用DB facade执行原生SQL查询_laravel DB facade原生SQL执行方法
简单实现Android文件上传
CSS3怎么给轮播图加过渡动画_transition加transform实现【技巧】
Laravel Eloquent性能优化技巧_Laravel N+1查询问题解决
米侠浏览器网页背景异常怎么办 米侠显示修复
如何在阿里云完成域名注册与建站?
Javascript中的事件循环是如何工作的_如何利用Javascript事件循环优化异步代码?

