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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • centos7执行ip addr命令ens33没有ip地址「建议收藏」

    centos7执行ip addr命令ens33没有ip地址「建议收藏」之前使用正常的虚拟机,突然的就连接不上了。执行ipaddr命令ens33没有ip地址查了几篇相关文章解决方法,主要有四种:mac地址问题 ONBOOT问题 uuid问题 NetworkManager问题目录mac地址问题ONBOOT问题uuid问题NetworkManager问题mac地址问题(我用的VMwareWorkstationP…

    2022年7月27日
    40
  • 【面试题】-java分布式及微服务面试题汇总

    【面试题】-java分布式及微服务面试题汇总目录1.CAP理论2.BASE理论3.接口的幂等性问题4.消息中间件如何解决消息丢失问题5.什么是分布式事务?分布式事务的类型有哪些?6.分布式事务的解决方案有哪些?7.Dubbo的服务请求失败怎么处理10.Soa和微服务架构有哪些区别?11.dubbo服务提供者,服务消费者需要配置哪些信息?12.Dubbo有哪些负载均衡策略13.Redis的持久化方式…

    2022年6月12日
    37
  • 基于Python的频谱分析(一)

    基于Python的频谱分析(一)

    2021年11月21日
    39
  • 如何理解无偏估计量_无偏估计量是唯一的吗

    如何理解无偏估计量_无偏估计量是唯一的吗现实中常常有这样的问题,比如,想知道全体女性的身高均值 ,但是没有办法把每个女性都进行测量,只有抽样一些女性来估计全体女性的身高:那么根据抽样数据怎么进行推断?什么样的推断方法可以称为“好”?1无偏性比如说我们采样到的女性身高分别为:那么:是对 不错的一个估计,为什么?因为它是无偏估计。首先,真正的全体女性的身高均值 ,我们是不知道,只有上帝才知道,在图中就画…

    2022年10月22日
    0
  • leetcode 最长有效括号_leetcode 三数之和

    leetcode 最长有效括号_leetcode 三数之和给你一个只包含 ‘(’ 和 ‘)’ 的字符串,找出最长有效(格式正确且连续)括号子串的长度。示例 1:输入:s = “(()”输出:2解释:最长有效括号子串是 “()”示例 2:输入:s = “)()())”输出:4解释:最长有效括号子串是 “()()”示例 3:输入:s = “”输出:0题解括号匹配:(看作+1,)看作-1,所有满足条件的括号应该是前缀和>=0,并且总和==0class Solution {public: const int INF =

    2022年8月9日
    5

发表回复

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

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