微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vue 登录滑动验证实现代码

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

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

rush:js;"> Box" id="code-Box">

>>>

vue代码

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'],false); document.addEventListener(BoxEven['2'],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; }

调用

rush:js;"> mounted(){ var _this = this; // window.addEventListener('load',function(){ //code是后台传入的验证字符串 var code = "jsaidaisd656",codeFn = new _this.moveCode(code,_this); // }); }

验证样式

rush:js;"> .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 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 登录滑动验证实现代码。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持

原文地址:https://www.jb51.cc/vue/30774.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐