温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用vue怎么实现登录滑动验证

发布时间:2021-05-31 18:20:51 来源:亿速云 阅读:290 作者:Leah 栏目:web开发

这期内容当中小编将会给大家带来有关使用vue怎么实现登录滑动验证,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

vue代码

//获取元素距离页面边缘的距离
getOffset(box,direction){
var setDirection = (direction == 'top') ? 'offsetTop' : 'offsetLeft' ;
var offset = box[setDirection];
var parentBox = box.offsetParent;
while(parentBox){
offset+=parentBox[setDirection];
parentBox = parentBox.offsetParent;
}
parentBox = null;
return parseInt(offset);
},
 moveCode(code,_this){
var fn = {codeVluae : code};
var box = document.querySelector("#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') ? e.touches[0] : e || window.event;
endX = e.clientX - goX;
endX = (endX > 0) ? (endX > evenWidth) ? evenWidth : endX : 0;
if(endX > evenWidth * 0.7){
progress.innerText = '松开验证';
progress.style.backgroundColor = "#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') ? 'offsetTop' : 'offsetLeft' ;
var offset = box[setDirection];
var parentBox = box.offsetParent;
while(parentBox){
offset+=parentBox[setDirection];
parentBox = parentBox.offsetParent;
}
parentBox = null;
return parseInt(offset);
};
evenBox.addEventListener(boxEven['0'], function(e) {
e = (boxEven['0'] == 'touchstart') ? e.touches[0] : e || window.event;
goX = e.clientX,
offsetLeft = getOffset(box,'left'),
deviation = this.clientWidth,
evenWidth = box.clientWidth - deviation,
endX;
document.addEventListener(boxEven['1'],moveFn,false);
document.addEventListener(boxEven['2'],removeFn,false);
},false);
fn.setCode = function(code){
if(code)
fn.codeVluae = code;
}
fn.getCode = function(){
return fn.codeVluae;
}
fn.resetCode = function(){
evenBox.removeAttribute('style');
progress.removeAttribute('style');
codeInput.value = '';
};
return fn;
 }

调用

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怎么实现登录滑动验证了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue
AI