本文實(shí)例為大家分享了JavaScript實(shí)現(xiàn)登錄滑塊驗(yàn)證的具體代碼,供大家參考,具體內(nèi)容如下
html代碼
1
2
3
4
5
6
7
8
|
< div class = "login-select" > < div v-show = "errselectFlag" id = "err-select" ></ div > < p id = "title-p" >按住滑塊,拖拽驗(yàn)證</ p > < div id = "left-select" ></ div > < div id = "right-select" > < i id = "icon-dui" class = "iconfont icon-right" ></ i > </ div > </ div > |
javascript代碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// 滑塊驗(yàn)證 var oRight = document.getElementById( "right-select" ); var bg = document.getElementById( "left-select" ); var title = document.getElementById( "title-p" ); var i = document.getElementById( "icon-dui" ); oRight.onmousedown = function (e) { var downX = e.clientX; //按下按鈕后與窗口的x軸間距 // 鼠標(biāo)移動事件 oRight.onmousemove = function (e) { if (e.clientX != 240) { oRight.style.left = 0 + "px" ; bg.style.left = 0 + "px" ; } var moveX = e.clientX - downX; //滑動的時候距離窗口的x軸的間距 //只有在大于0的時候才拖動,否則會出現(xiàn)反向拖動 if (moveX > 0) { oRight.style.left = moveX + "px" ; //滑塊與左邊的距離 bg.style.width = moveX + "px" ; //背景的寬度就是滑塊距離左邊的位置 if (moveX >= 280 - oRight.offsetWidth) { i.className = "iconfont icon-xingzhuang" ; i.style.color = "rgb(86, 192, 15)" ; title.innerText = "驗(yàn)證通過" ; title.style.color = "#fff" ; oRight.onmousemove = null ; oRight.onmousedown = null ; } } }; }; |
style代碼
注:樣式為sass文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
*{ margin : 0 ; padding : 0 ;box-sizing: border-box;} .login-select { width : 280px ; height : 40px ; margin : auto ; margin-top : 20px ; margin-left : 15px ; margin-right : 15px ; text-align : center ; line-height : 40px ; background : rgba( 134 , 134 , 131 , 0.6 ); display : flex; position : relative ; #err-select { width : 138px ; height : 38px ; position : absolute ; right : -152px ; top : 0 ; color : #fff ; font-size : 12px ; border-radius: 5px ; line-height : 38px ; text-align : center ; background : rgb ( 177 , 71 , 71 ); } #title-p { text-align : center ; line-height : 40px ; width : 100% ; height : 100% ; font-size : 14px ; position : absolute ; } #left-select { width : 0 ; height : 100% ; transform: translate( 0.3 s); background : rgb ( 86 , 192 , 15 ); } #right-select { width : 40px ; height : 40px ; background : #fff ; color : #aaaa ; text-align : center ; line-height : 40px ; border : 1px solid #ccc ; position : absolute ; cursor : move ; } } |
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/weixin_49684597/article/details/115613523