Browse Source

On enter pressed --> navigate

Baptiste Marty 3 years ago
parent
commit
d8566245a1
2 changed files with 16 additions and 10 deletions
  1. 1
    1
      CSS/menu.css
  2. 15
    9
      JAVASCRIPT/menu.js

+ 1
- 1
CSS/menu.css View File

@@ -130,7 +130,6 @@ main{
130 130
             background-image: linear-gradient( #5EE283, #057B26);
131 131
             border-radius: 4vw;
132 132
             box-shadow: -0.2vw 0.2vw 0.2vw rgba(255, 255, 255, 0.7);
133
-            padding:0.8vw 0.8vw 0.5vw 0.8vw;
134 133
             opacity:0;
135 134
             animation:fade-text 1s forwards;
136 135
             animation-delay:6s;
@@ -138,6 +137,7 @@ main{
138 137
         }
139 138
         
140 139
         #buttonTxt {
140
+            padding:0.8vw 0.8vw 0.5vw 0.8vw;
141 141
             text-decoration:none;
142 142
             margin:0;
143 143
             color : black;

+ 15
- 9
JAVASCRIPT/menu.js View File

@@ -14,16 +14,21 @@ function initError(){
14 14
     errorTxt.innerText = ""
15 15
 }
16 16
 
17
-function handleNavigation(){
18
-    console.log(pseudo);
19
-     if (pseudo){
20
-         initError();
21
-         button.childNodes[1].setAttribute("href","etrange_decouverte.html")
22
-         localStorage.setItem("pseudo",pseudo);
23
-     } else {
17
+function handleNavigation(event){
18
+    
19
+    if(event.keyCode == 13){
20
+        pseudo = pseudoInput.value;
21
+        console.log(pseudo);
22
+    if (pseudo){
23
+        initError();
24
+        button.childNodes[1].setAttribute("href","etrange_decouverte.html")
25
+        localStorage.setItem("pseudo",pseudo);
26
+        button.childNodes[1].click()
27
+    } else {
24 28
         button.childNodes[1].removeAttribute("href")
25 29
         errorTxt.innerText = "Veuillez rentrer un pseudo svp"
26
-     }
30
+    }
31
+    }
27 32
 }
28 33
 
29 34
 function handlePseudoChange(event){
@@ -36,4 +41,5 @@ initError();
36 41
 
37 42
 // event listeners
38 43
 pseudoInput.addEventListener("change",handlePseudoChange)
39
-button.addEventListener("click",handleNavigation)
44
+pseudoInput.addEventListener("keypress",handleNavigation)
45
+button.addEventListener("click",handleNavigation)

Loading…
Cancel
Save