vue 滑动验证码(vue登陆如何获取token)

之前别人都是用jq写的,自己整理了一下开始使用<el-form-itemlabel="验证"><divclass="form-inline-input"><divclass="code-box"id="code-box">

大家好,又见面了,我是你们的朋友全栈君。

之前别人都是用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;
    }

调用

mounted(){
var _this
=
this;
// window.addEventListener(‘load’,function(){
//code是后台传入的验证字符串
var code
=
“jsaidaisd656”,
codeFn
=
new
_this.
moveCode(code,_this);
// });
}

验证样式

.form-inline-input{
  
border:
1
px
solid
#dadada;
border-radius:
5
px;
}
.form-inline-input
input,
.code-box{
  
padding:
0
3
px;
width:
298
px;
height:
40
px;
color:
#fff;
text-shadow:
1
px
1
px
1
px
black;
background:
#efefef;
border:
0;
border-radius:
5
px;
  
outline:
none;
}
.code-box{
  
position:
relative;
}
.code-box
p,
.code-box
span{
  
display:
block;
  
position:
absolute;
  
left:
0;
  
height:
40
px;
  
text-align:
center;
  
line-height:
40
px;
  
border-radius:
5
px;
padding:
0;
margin:
0;
}
.code-box
span{
  
width:
40
px;
  
background-color:
#fff;
  
font-size:
16
px;
  
cursor:
pointer;
margin-right:
1
px;
}
.code-box
p{
  
width:
0;
  
background-color:
#FFFF99;
  
overflow:
hidden;
  
text-indent:
-20
px;
  
transition:
background
1
s
ease-in;
}
.code-box
.code-input{
  
display:
none;
}
.code-box
.code-input{
  
display:
none;
}

.form-inline-input{
  
border:
1
px
solid
#dadada;
border-radius:
5
px;
}
.form-inline-input
input,
.code-box{
  
padding:
0
3
px;
width:
298
px;
height:
40
px;
color:
#fff;
text-shadow:
1
px
1
px
1
px
black;
background:
#efefef;
border:
0;
border-radius:
5
px;
  
outline:
none;
}
.code-box{
  
position:
relative;
}
.code-box
p,
.code-box
span{
  
display:
block;
  
position:
absolute;
  
left:
0;
  
height:
40
px;
  
text-align:
center;
  
line-height:
40
px;
  
border-radius:
5
px;
padding:
0;
margin:
0;
}
.code-box
span{
  
width:
40
px;
  
background-color:
#fff;
  
font-size:
16
px;
  
cursor:
pointer;
margin-right:
1
px;
}
.code-box
p{
  
width:
0;
  
background-color:
#FFFF99;
  
overflow:
hidden;
  
text-indent:
-20
px;
  
transition:
background
1
s
ease-in;
}
.code-box
.code-input{
  
display:
none;
}
.code-box
.code-input{
  
display:
none;
}

展示

vue 滑动验证码(vue登陆如何获取token)vue 滑动验证码(vue登陆如何获取token)

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

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/129433.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 1073. 树的中心(树形dp)[通俗易懂]

    1073. 树的中心(树形dp)[通俗易懂]给定一棵树,树中包含 n 个结点(编号1~n)和 n−1 条无向边,每条边都有一个权值。请你在树中找到一个点,使得该点到树中其他结点的最远距离最近。输入格式第一行包含整数 n。接下来 n−1 行,每行包含三个整数 ai,bi,ci,表示点 ai 和 bi 之间存在一条权值为 ci 的边。输出格式输出一个整数,表示所求点到树中其他结点的最远距离。数据范围1≤n≤10000,1≤ai,bi≤n,1≤ci≤105 输入样例: 5 2 1 1 3 2 1 4 3 1 5 1

    2022年8月8日
    4
  • tomcat7下载安装

    tomcat7下载安装进入apache官网下载tomcat7在最左边的找到download下的tomcat7并点击。选择“32-bit/64-bitWindowsServerInstaller”下载.下载完成后,将安装文件移动到本地硬盘D安装tomcat7,双击下载后的文件,进入安装界面,点next,继续IAgree,组件选择使用默认选项,点next,最后如图所示:

    2022年5月12日
    134
  • 手机安装busybox教程(去除busybox的xbin连接)

    Busybox,大家应该有所耳闻,其中集成了众多linux的命令和工具。有时候在手机上想使用find,grep等命令但是手机不支持。这时可以在手机上安装busybox.使用方法:1.确定手机型号cpu的指令集,cat/proc/cpuinfo如armv7,armv4,armv6,去网上下载二进制busybox文件。下载地址:http:

    2022年4月12日
    176
  • dumpbin的使用方法_dumpbin 的基础使用

    dumpbin的使用方法_dumpbin 的基础使用oneNeko于2020-10-17发布要查看exe依赖哪些动态库或某个DLL包含哪些接口函数依赖哪些动态库,可以使用depends工具或者vs自带的dumpbin工具,这里使用vs自带的dumpbin启动dumpbin是使用vs命令行的,有两种方法打开:1、打开vs,工具-命令行-开发者命令提示2、开始菜单-visualstdioxxxx-命令提示符使用使用很简单,语法如下:DUMPB…

    2022年6月19日
    34
  • 检查文件是否有更新,监控文件状态

    检查文件是否有更新,监控文件状态

    2021年9月17日
    49
  • CSS 相邻兄弟选择器

    相邻兄弟选择器(Adjacentsiblingselector)可选择紧接在另一元素后的元素,且二者有相同父元素。选择相邻兄弟如果需要选择紧接在另一个元素后的元素,而且二者有相同的父元素,可以使用

    2021年12月20日
    60

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号