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


相关推荐

  • 【读书笔记】——奇点临近「建议收藏」

    做一个积极的人编码、改bug、提升自己我有一个乐园,面向编程,春暖花开!文章目录第一章 六大纪元第二章 技术进化理论:加速回归定律第三章 达到人脑的计算能力=================================================对人工智能感兴趣的伙伴,分享一个我朋友的人工智能教程。零基础!通俗易懂!风趣幽默!大家可以看看是否对自己有帮助,点击这里查看教程。…

    2022年2月28日
    45
  • 线性分类模型

    线性分类模型

    2021年6月8日
    100
  • 一文概括常用图像处理算法

    一文概括常用图像处理算法本文总结了11种常用的图像处理算法,包含了预处理算法以及检测算法,并介绍了一些常用的开发库。一、算法(预处理算法、检测算法)在采集完图像后,首先会对图像进行预处理操作。1、图像变换(空域与频域、几何变换、色度变换、尺度变换)2、图像增强3、纹理分析(取骨架、连通性)4、图像分割5、图像特征6、图像/模板匹配7、色彩分析8、图像数据编码压缩和传输9、表面缺陷目标识别算法10、图像分类(识别)11、图像复原二、现有的视觉检测软件/库三、HSV颜色识别-HSV基本颜色分量范围

    2022年5月13日
    49
  • vue-router 详解

    vue-router 详解文章目录1、认识vue-router2、安装和使用vue-router1、认识vue-router目前前端流行的三大框架,都有自己的路由实现:Angular的ngRouterReact的ReactRouterVue的vue-routervue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用。我们可以访问其官方网站对其进行学习:https://router.vuejs.org/zh/vue-router是基于路由和组件的路由用户设定访问

    2022年7月11日
    24
  • datagrip 激活码【注册码】

    datagrip 激活码【注册码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月18日
    58
  • 基于Rust-vmm实现Kubernetes运行时[通俗易懂]

    基于Rust-vmm实现Kubernetes运行时[通俗易懂]随着容器及K8s的广泛使用,越来越多的容器安全与隔离问题被暴露出来,如:容器逃逸、水平攻击、DDos攻击等严重威胁了办公和生产环境的安全与稳定,影响了业务的正常运行。安全容器技术孕育而生,产生了kata、gVisor、unikernel等多种安全容器方案。本文旨在介绍各种安全容器方案,分析各方案特点,结合腾讯在容器安全领域的实践,帮助读者选择适合自身特性的容器运行时。同时引入Rust-VMM项目,介绍Rust-VMM技术和生态,演示如何使用K8s调度和启用Rust-VMM安全容器运行时,展望以Rust语

    2025年11月20日
    2

发表回复

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

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