最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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");
//默認(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 = '松開驗證';
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;
}

總結(jié)

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

相關(guān)文章

  • 使用vue實現(xiàn)簡單鍵盤的示例(支持移動端和pc端)

    使用vue實現(xiàn)簡單鍵盤的示例(支持移動端和pc端)

    這篇文章主要介紹了使用vue實現(xiàn)簡單鍵盤的示例(支持移動端和pc端),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • vue中watch如何同時監(jiān)聽多個屬性

    vue中watch如何同時監(jiān)聽多個屬性

    這篇文章主要介紹了vue中watch如何同時監(jiān)聽多個屬性,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • 使用elementUI實現(xiàn)將圖片上傳到本地的示例

    使用elementUI實現(xiàn)將圖片上傳到本地的示例

    今天小編就為大家分享一篇使用elementUI實現(xiàn)將圖片上傳到本地的示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • Vue中保存用戶登錄狀態(tài)實例代碼

    Vue中保存用戶登錄狀態(tài)實例代碼

    本篇文章主要介紹了Vue中保存用戶登錄狀態(tài)實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下。、
    2017-06-06
  • vue使用echarts圖表的詳細(xì)方法

    vue使用echarts圖表的詳細(xì)方法

    這篇文章主要為大家詳細(xì)介紹了vue使用echarts圖表的詳細(xì)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Element Dropdown下拉菜單的使用方法

    Element Dropdown下拉菜單的使用方法

    這篇文章主要介紹了Element Dropdown下拉菜單的使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Vue中@click.native的使用方法及場景

    Vue中@click.native的使用方法及場景

    在組件中時常看到@click.native,在項目中遇到后,簡單介紹下,這篇文章主要給大家介紹了關(guān)于Vue中@click.native的使用方法及場景的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • vue3使用百度地圖超詳細(xì)圖文教程

    vue3使用百度地圖超詳細(xì)圖文教程

    這篇文章主要給大家介紹了關(guān)于vue3使用百度地圖的相關(guān)資料,最近一個項目要用到地圖,因為微信小程序用的也是百度地圖,所以想著網(wǎng)頁端也用百度地圖,需要的朋友可以參考下
    2023-07-07
  • vue中v-for數(shù)據(jù)狀態(tài)值變了,但是視圖沒改變的解決方案

    vue中v-for數(shù)據(jù)狀態(tài)值變了,但是視圖沒改變的解決方案

    這篇文章主要介紹了vue中v-for數(shù)據(jù)狀態(tài)值變了,但是視圖沒改變的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • 如何解決element-ui中select下拉框popper超出彈框問題

    如何解決element-ui中select下拉框popper超出彈框問題

    這篇文章主要介紹了如何解決element-ui中select下拉框popper超出彈框問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-04-04

最新評論

康乐县| 济南市| 安远县| 邹平县| 九龙坡区| 通江县| 寻乌县| 西平县| 达日县| 淮北市| 昂仁县| 绩溪县| 海丰县| 江油市| 彭水| 河池市| 南和县| 林西县| 体育| 武威市| 太保市| 乐东| 镇江市| 宿迁市| 马公市| 汝城县| 高阳县| 邛崃市| 霍山县| 乾安县| 冷水江市| 博罗县| 遵化市| 丹巴县| 宜都市| 南江县| 翼城县| 宣恩县| 盱眙县| 和林格尔县| 原阳县|