Repository navigation
Expand file tree
/
Copy pathDropdown.js
More file actions
60 lines (48 loc) · 1.86 KB
/
Copy pathDropdown.js
File metadata and controls
60 lines (48 loc) · 1.86 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
//Global variables
let increment = -5.1;
let dropped = false;
let Go;
//Use instead of disabling button
let animating = false;
let requestedDrop = false;
function Read(){ //Puts information in an alert //Enable button from the HTML file
let Drop = document.getElementById('Drop');
alert(Drop.style.height);
alert(dropped);
}
function Dropdown(){ //Called by Dropdown button
let Drop = document.getElementById('Drop'); //Gets Navigation menu HTML element
if(!animating){ //Checks if the the menu is opening or closing
animating = true; //Says that the menu is animating
if(!dropped){ //Checks if it is opened or closed
Go = setInterval(function(){ //Starts loop with time
increment = increment + 0.1; //Increments
Drop.style.height = (150/(1 + Math.pow(2.718, -increment))); //Sets navigation menu height
if(parseInt(Drop.style.height)>=130){ //Checks for end
End(); //Ends loop
dropped = true; //Tells Dropdown() that the menu is open
}
}, 1);
}else{
Go = setInterval(function(){ //Starts loop with time
increment = increment - 0.1; //Increments
Drop.style.height = (150/(1 + Math.pow(2.718, -increment))); //Sets navigation menu height
if(parseInt(Drop.style.height)<=0){ //Checks for end
End(); //Ends loop
dropped = false; //Tells Dropdown() that the menu is open
}
}, 1);
}
}else{
requestedDrop = true;
}
}
function End(){//Ends loop
clearInterval(Go); //Ends loop
animating = false; //Tells Dropdown() that the menu is animating
if(requestedDrop){ //To go again if button is reclicked while animating | Only once per cycle
Dropdown();
}else{
requestedDrop = false;
}
}