在没给大家讲解实现代码之前,先给大家分享效果图:
之前别人都是用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 登录滑动验证实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]
- 柏菲-《好歌30年壹》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 大自然音乐系列《水舞》[WAV/CUE/分轨][424.3MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]