网络编程 
首页 > 网络编程 > 浏览文章

vue 登录滑动验证实现代码

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )

在没给大家讲解实现代码之前,先给大家分享效果图:

vue 登录滑动验证实现代码

vue 登录滑动验证实现代码

之前别人都是用jq写的,自己整理了一下开始使用

<el-form-item label="验证">
<div class="form-inline-input">
<div class="code-box" id="code-box">
<input type="text" name="code" class="code-input" />
<p></p>
<span</span>
</div>
</div>
</el-form-item>

vue代码

//获取元素距离页面边缘的距离
getOffset(box,direction){
var setDirection = (direction == 'top') "#code-box"),
progress = box.querySelector("p"),
codeInput = box.querySelector('.code-input'),
evenBox = box.querySelector("span");
//默认事件
var boxEven = ['mousedown','mousemove','mouseup'];
//改变手机端与pc事件类型
if(typeof document.ontouchstart == 'object'){
boxEven = ['touchstart','touchmove','touchend'];
}
var goX,offsetLeft,deviation,evenWidth,endX;
function moveFn(e){
e.preventDefault();
e = (boxEven['0'] == 'touchstart') "#66CC66";
}else{
progress.innerText = '';
progress.style.backgroundColor = "#FFFF99";
}
progress.style.width = endX+deviation+'px';
evenBox.style.left = endX+'px';
}
function removeFn() {
document.removeEventListener(boxEven['2'],removeFn,false);
document.removeEventListener(boxEven['1'],moveFn,false);
if(endX > evenWidth * 0.7){
progress.innerText = '验证成功';
progress.style.width = evenWidth+deviation+'px';
evenBox.style.left = evenWidth+'px'
codeInput.value = fn.codeVluae;
evenBox.onmousedown = null;
_this.ruleForm.verification = true;
}else{
progress.style.width = '0px';
evenBox.style.left = '0px';
}
};
function getOffset(box,direction){
var setDirection = (direction == 'top') "htmlcode">
mounted(){
var _this = this;
// window.addEventListener('load',function(){
//code是后台传入的验证字符串
var code = "jsaidaisd656",
codeFn = new _this.moveCode(code,_this);
// });
}

验证样式

.form-inline-input{
 border:1px solid #dadada;
border-radius:5px;
}
.form-inline-input input,
.code-box{
 padding: 0 3px;
width: 298px;
height: 40px;
color: #fff;
text-shadow: 1px 1px 1px black;
background: #efefef;
border: 0;
border-radius: 5px;
 outline: none;
}
.code-box{
 position: relative;
}
.code-box p,
.code-box span{
 display:block;
 position: absolute;
 left: 0;
 height: 40px;
 text-align: center;
 line-height: 40px;
 border-radius: 5px;
padding:0;
margin:0;
}
.code-box span{
 width: 40px;
 background-color:#fff;
 font-size: 16px;
 cursor: pointer;
margin-right:1px;
}
.code-box p{
 width: 0;
 background-color: #FFFF99;
 overflow: hidden;
 text-indent: -20px;
 transition: background 1s ease-in;
}
.code-box .code-input{
 display: none;
}
.code-box .code-input{
 display: none;
}
.form-inline-input{
 border:1px solid #dadada;
border-radius:5px;
}
.form-inline-input input,
.code-box{
 padding: 0 3px;
width: 298px;
height: 40px;
color: #fff;
text-shadow: 1px 1px 1px black;
background: #efefef;
border: 0;
border-radius: 5px;
 outline: none;
}
.code-box{
 position: relative;
}
.code-box p,
.code-box span{
 display:block;
 position: absolute;
 left: 0;
 height: 40px;
 text-align: center;
 line-height: 40px;
 border-radius: 5px;
padding:0;
margin:0;
}
.code-box span{
 width: 40px;
 background-color:#fff;
 font-size: 16px;
 cursor: pointer;
margin-right:1px;
}
.code-box p{
 width: 0;
 background-color: #FFFF99;
 overflow: hidden;
 text-indent: -20px;
 transition: background 1s ease-in;
}
.code-box .code-input{
 display: none;
}
.code-box .code-input{
 display: none;
}

总结

以上所述是小编给大家介绍的vue 登录滑动验证实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

上一篇:element-ui中的select下拉列表设置默认值方法
下一篇:Vue 实现拖动滑块验证功能(只有css+js没有后台验证步骤)
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网