-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
91 lines (79 loc) · 2.01 KB
/
Copy pathscript.js
File metadata and controls
91 lines (79 loc) · 2.01 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const circleNumber = document.querySelector(".circle-number")
const input = document.querySelector(".input-code input")
const btnStart = document.querySelector(".btn-group .start")
const btnRestar = document.querySelector(".btn-group .reset")
const passKey = document.querySelector(".key-wrapper")
const tip = document.querySelector(".tip-number")
const arr = []
let loop
// add event
input.addEventListener("input",function(){
this.value = this.value.slice(0,4)
})
btnRestar.addEventListener("click",function(){
reset()
})
btnStart.addEventListener("click",function(){
simulation()
})
createNumber()
// function state
async function createNumber(){
for(let i = 0;i<10;i++){
let span = document.createElement("span")
span.innerHTML = i
arr.push(span)
circleNumber.appendChild(span)
}
arr.forEach(async(element,i)=>{
await delay(100)
element.style.transform = `rotate(${(i*36)}deg)`
})
}
function delay(sec = 1000){
return new Promise((res,rej)=>{
setTimeout(()=>{
res()
},sec)
})
}
// function animate
async function show(element,time = 1000){
element.classList.remove("show")
}
async function show(element,time = 1000){
element.classList.add("show")
await delay(time)
element.classList.remove("show")
}
function changeText(element,text){
element.innerHTML = text;
}
function disableElement(element){
element.disabled = !element.disabled
}
// function alogorithm
function simulation(){
if( input.value.length != 4 ){
changeText(tip,"must contain 4 characters")
show(tip,3000)
return false
}
disableElement(btnStart)
let text = input.value
let i = 0
passKey.style.transform = `rotate(${(text[i]*36)}deg)`;
loop = setInterval(()=>{
i++
passKey.style.transform = `rotate(${(text[i]*36)}deg)`;
if(i==text.length){
clearInterval(loop)
}
},3000)
}
function reset(){
passKey.style.transform = `rotate(${(0*36)}deg)`;
input.value = ""
disableElement(btnStart)
clearInterval(loop)
}