国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

vue 登錄滑動(dòng)驗(yàn)證實(shí)現(xiàn)代碼

2019-11-19 13:10:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

在沒(méi)給大家講解實(shí)現(xiàn)代碼之前,先給大家分享效果圖:

之前別人都是用jq寫的,自己整理了一下開(kāi)始使用

<el-form-item label="驗(yàn)證"><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代碼

//獲取元素距離頁(yè)面邊緣的距離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");//默認(rèn)事件var boxEven = ['mousedown','mousemove','mouseup'];//改變手機(jī)端與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 = '松開(kāi)驗(yàn)證';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 = '驗(yàn)證成功';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; }

調(diào)用

mounted(){var _this = this;// window.addEventListener('load',function(){//code是后臺(tái)傳入的驗(yàn)證字符串var code = "jsaidaisd656",codeFn = new _this.moveCode(code,_this);// });}

驗(yàn)證樣式

.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;}

總結(jié)

以上所述是小編給大家介紹的vue 登錄滑動(dòng)驗(yàn)證實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 永州市| 宁南县| 宁明县| 航空| 鹰潭市| 北辰区| 乌拉特中旗| 永定县| 资阳市| 高密市| 葵青区| 怀集县| 临江市| 固原市| 焦作市| 卫辉市| 沽源县| 崇仁县| 新丰县| 三台县| 丹棱县| 马龙县| 平顶山市| 措勤县| 汕尾市| 保靖县| 临清市| 张家港市| 滁州市| 宿迁市| 潼南县| 宁海县| 湘潭市| 尚志市| 合作市| 徐水县| 无极县| 板桥市| 山阴县| 青河县| 彝良县|