欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue 登錄滑動驗證實現(xiàn)代碼

 更新時間:2018年08月24日 10:03:08   作者:前端小白16  
這篇文章主要介紹了vue 登錄滑動驗證實現(xiàn)代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

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

之前別人都是用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') ? '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;
 }

調(diào)用

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 登錄滑動驗證實現(xiàn)代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • 使用vue3+vite導入圖片路徑錯亂問題排查及解決

    使用vue3+vite導入圖片路徑錯亂問題排查及解決

    使用vue3+vite開發(fā)的時候,導入svg圖片時,同一個文件夾下的文件,其中一個路徑正常解析,另一個不行,更改文件名之后,該圖片文件就可以正常解析了,本文給大家介紹了使用vue3+vite導入圖片路徑錯亂問題排查及解決,需要的朋友可以參考下
    2024-03-03
  • 從vue源碼解析Vue.set()和this.$set()

    從vue源碼解析Vue.set()和this.$set()

    這篇文章主要介紹了從vue源碼看Vue.set()和this.$set()的相關知識,我們先來從Vue提供的Vue.set()和this.$set()這兩個api看看它內(nèi)部是怎么實現(xiàn)的。感興趣的朋友跟隨小編一起看看吧
    2018-08-08
  • Vue新手指南之創(chuàng)建第一個vue-cli腳手架程序

    Vue新手指南之創(chuàng)建第一個vue-cli腳手架程序

    vue-cli 是一個官方發(fā)布 vue.js 項目腳手架,使用 vue-cli 可以快速創(chuàng)建 vue 項目。這篇文章主要給大家介紹了關于Vue新手指南之創(chuàng)建第一個vue-cli程序的相關資料,需要的朋友可以參考下
    2021-05-05
  • vue中methods、mounted等的使用方法解析

    vue中methods、mounted等的使用方法解析

    這篇文章主要介紹了vue中methods、mounted等的使用方法解析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • vue?elementUi中的tabs標簽頁使用教程

    vue?elementUi中的tabs標簽頁使用教程

    Tabs 組件提供了選項卡功能,默認選中第一個標簽頁,下面這篇文章主要給大家介紹了關于vue?elementUi中的tabs標簽頁使用的相關資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下
    2023-03-03
  • Vue.js中數(shù)組變動的檢測詳解

    Vue.js中數(shù)組變動的檢測詳解

    這篇文章給大家主要介紹了Vue.js中數(shù)組變動的檢測,文中給出了詳細的示例代碼和過程介紹,相信會對大家的理解和學習很有幫助,有需要的朋友們下面來一起看看吧。
    2016-10-10
  • 使用 Vue 3 的 createApp方法初始化應用的基本步驟

    使用 Vue 3 的 createApp方法初始化應用的基本步驟

    createApp 是 Vue 3 引入的全局 API,用于創(chuàng)建一個應用實例,這篇文章主要介紹了如何使用 Vue 3 的 createApp方法初始化應用,通過 createApp 方法,我們從 Vue 3 的基本初始化開始,擴展到插件的應用、多個應用實例的創(chuàng)建等,需要的朋友可以參考下
    2024-05-05
  • 講解vue-router之什么是嵌套路由

    講解vue-router之什么是嵌套路由

    這篇文章主要介紹了講解vue-router之什么是嵌套路由,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • vue開發(fā)心得和技巧分享

    vue開發(fā)心得和技巧分享

    這篇文章主要為大家分享了vue開發(fā)心得和技巧,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • vue數(shù)據(jù)更新了但在頁面上沒有顯示出來的解決方法

    vue數(shù)據(jù)更新了但在頁面上沒有顯示出來的解決方法

    有時候 vue 無法監(jiān)聽到數(shù)據(jù)的變化,導致數(shù)據(jù)變化但是視圖沒有變化,也就是數(shù)據(jù)更新了,但在頁面上沒有顯示出來,所以本文給出了三種解決方法,通過代碼示例介紹的非常詳細,需要的朋友可以參考下
    2023-12-12

最新評論