Bonjour,

Je réalise mon portfolio photo et j'avais pour idée de mettre la barre de navigation à gauche lorsqu'on est desktop et au top pour les smartphones

En gros, j'ai employé les mediaqueries avec la limite arbitraire de 850 px.

Tout fonctionne nickel, à part à ce moment : je suis à moins de 850 px, je passe à plus de 851 px et le menu est fermé.

Pour résumer, en large device, le menu est caché à gauche par l'intermédiaire d'un transform translate de la taille du menu à -260 px. Il se rélève par un transform translate à 0px. J'ai initialement positionné par la feuille CSS à -260 et ensite jquery prend le relais pour le changement de propriété CSS par transform translate.

En small device, c'est plus simple, il s'agit d'un simple .hide() et .show(). Et puis, par jQuery, j'indique les propriétés transform.

Mon gros problème, lorsque je passe de small à large device avec le menu fermé, les propriétés transform ne se remettent pas comme au chargement initial. J'ai beau essayé de mettre le transform translate -260 via jquery, cela décale tout. BRef, un véritable casse tête, je m'en sors pas, et je me demandais si un oeil avisé pouvait me donner un coup de pouce ...

Le site web :

http://photo.sebgac.com

La feuille de style :

Code css : Sélectionner tout - Visualiser dans une fenêtre à part
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
 
/* Note : les border: 1px solid white servent pour situer les boites */
 
/* On reset les paramètres */
 
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
 
/* Style général + définition des premières div en flex */
 
body {
  width: 100%;
  background-color: black;
  color: white;
  /* font-family: 'Roboto Mono', monospace; */
  font-family: 'PT Mono', monospace;
  letter-spacing: 0.23rem;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: inline-flex;
  overflow: hidden;
}
 
/* Style général des liens */
 
a {
  text-decoration: none;
  color: inherit;
}
 
/* Mise en inline flex des 2 div menuGauche et liseret */
 
header {
  display: inline-flex;
  /* transition-property: transform;
  transition-delay: 500ms; */
}
 
/* Style de la 1ere div du header */
 
.menuGauche {
  width: 240px;
  margin-left: 20px;
  /*       min-height: 100vh; */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transform: translate(-260px);
  transition-property: transform;
  transition-duration: 500ms;
}
 
.menuGauche h2 {
  /* border: 1px solid white; */
  padding: 20px 0;
  /* margin: auto; */
}
 
/* Dans la nav : flex column pour mettre en boite les div internes */
 
#titre1 {
  font-weight: lighter;
  transform: translate(-260px);
  transition-property: transform;
  transition-duration: 500ms;
}
 
.menuGauche nav {
  /* border: 1px solid white; */
  display: flex;
  flex-direction: column;
  margin-bottom: 10vh;
  margin-left: 10px;
  color: #939393;
  transform: translate(-260px);
  transition-property: transform;
  transition-duration: 500ms;
}
 
ul#categories {
  letter-spacing: 0.11rem;
}
 
ul#categories li {
  padding: 3px 0;
}
 
.menuGauche ul {
  /* border: 1px solid white; */
  flex-grow: 3;
  padding: 10px 0;
}
 
.menuGauche li {
  list-style: none;
}
 
/* Définition de l'animation pour les liens du menu */
 
.menuGauche li a, #about a {
  transition: all 0.5s ease-out;
}
 
.menuGauche li a:hover, #about a:hover {
  color: white;
}
 
a#street:focus, a#architecture:focus, a#portrait:focus, a#mariage:focus, .asie a:focus, .europe a:focus, .amsud a:focus, #about a:focus {
  color: white;
}
 
ul.continents {
  padding-left: 5px;
  font-size: 0.98rem;
}
 
/* Petite marge pour différencier les pays des continents */
 
.asie a, .europe a, .amsud a {
  padding-left: 10px;
}
 
/* Opacité 0 pour l'icone flèche, modifiée avec jQuery */
 
i.fas.fa-arrow-down, i.fas.fa-arrow-up {
  /* color:red; */
  /* opacity: 0; */
  font-size: 10px;
  vertical-align: middle;
}
 
/* Div contenant liens vers pages about / moi / contact ... */
 
#about {
  /* border: 1px solid white; */
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}
 
#about a {
  padding-top: 5px;
}
 
/* Style de la 2 div du header, le petit liseret */
 
.liseret {
  /*flex-grow: 1;*/
  width: 52px;
  min-height: 100vh;
  border-width: 0 1px 0 1px;
  border-color: #3a3a3a;
  border-style: solid;
  display: flex;
  flex-direction: column;
  transform: translate(-260px);
  transition: all 500ms;
  /*    align-content: space-between; */
}
 
.liseret:hover {
  background-color: #1e1e1e;
}
 
#menuburger {
  /* border: 1px solid white; */
  text-align: center;
  padding: 15px 0 15px 3px;
  transition: all 0.5s ease-out;
}
 
#menuburger:hover {
  color: #939393;
}
 
#portfolio {
  /* border: 1px solid white; */
  transform: rotate(-90deg) translate(22%, -479%);
  -moz-transform: rotate(-90deg) translate(22%, -465%);
  width: 447%;
  margin: auto;
}
 
/* 
 
// autre façon de spécifier une règle CSS en ciblant firefox
 
@-moz-document url-prefix() {
  #portfolio {
    transform: rotate(-90deg) translate(22%, -465%);
  }
} 
 
*/
 
/* Div Principale contenant le titre et le caroussel */
 
section {
  width: 96%;
  /* border: 1px solid white; */
  display: flex;
  flex-direction: column;
  /* transition-property: transform;
  transition-delay: 500ms;  */
}
 
section .titre {
  /* flex-grow: 1; */
  padding: 20px;
  text-align: center;
  transform: translate(-260px);
  transition-property: transform;
  transition-duration: 500ms;
}
 
section h2 {
  font-weight: lighter;
  padding-top: 5px;
  color: #939393;
  /* text-transform: uppercase; */
}
 
#caroussel {
  width: 100%;
  /* border: 1px solid white; */
  text-align: center;
  transform: translate(-260px);
  transition-property: transform;
  transition-duration: 500ms;
  display: flex;
  flex-direction: row;
}
 
#loader {
  display: none;
  position: absolute;
  top: 45%;
  left: 45%;
}
 
#loader img {
  width: 150px;
}
 
    @media screen and (max-width: 850px) {
 
      body {
        display: flex;
        flex-direction: column;
        overflow: scroll;
      }
      header {
        display: flex;
        flex-direction: column-reverse;
        /* border: 1px solid white; */
        border-bottom: 1px solid #3a3a3a;
        z-index: 2;
        background-color: black;
        padding-bottom: 48px;
        /* position: relative; */
      }
      .menuGauche {
        /* width:100%; */
        /* width: 220px; */
        margin-left: 0;
        transform: none;
        /* border: 1px solid white; */
        margin: auto;
        position: relative;
        top: 48px;
        background-color: black;
      }
      #titre1 {
        display: none
      }
      .menuGauche nav {
        transform: none;
        /* border: 1px solid white; */
        margin-bottom: 0;
        margin-left: 0;
        padding-top: 10px;
        /* position: relative; */
        /* top: 48px; */
        /* background-color: black;*/
        /* width: 100%; */
        /* text-align: center; */
        /* border-bottom: 1px solid white; */
      }
      i.fas.fa-arrow-down, i.fas.fa-arrow-up {
        /* color:red; */
        opacity: 1;
      }
      .liseret {
        border-bottom: 1px solid;
        width: 100%;
        min-height: 5vh;
        flex-direction: row-reverse;
        transform: none;
        /* border: 1px solid white; */
        padding: 0 10px;
        border-bottom: 1px solid;
        position: absolute;
        top: 0px;
        background-color: black;
      }
      .liseret:hover {
        background-color: black;
      }
      #portfolio {
        transform: none;
        width: none;
      }
      section {
        width: 100%;
        margin-left: 2%;
        position: absolute;
        /* top: 12vh; */
        z-index: 1;
      }
      section .titre {
        /* display:none; */
        transform: none;
        font-size: 0.5rem;
      }
      section #caroussel {
        /* display:none; */
        /* border: 1px solid white; */
        width: 96%;
        transform: none;
        flex-direction: column;
      }
      @media screen and (orientation: portrait) {
        #loader {
          left: 30%;
        }
      }
      @media screen and (orientation: landscape) {
        /* le titre est caché lorsqu'on passe en landscape */
        section .titre {
          display: none;
        }
        #menuburger {
          padding-right: 3px;
        }
        #loader {
          left: 37%;
        }
      }
    }

Le script (j'ai sélectionné les parties concernées)

Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
function initLoadSmall() {
 
        if (window.matchMedia("(max-width: 850px)").matches) {
 
            // de base, le menu est caché
            $('.menuGauche').hide();
            //on cache la bordure du liseret pour éviter de surcharger
            $('.liseret').css('border-bottom', '0');
        }
    }
 
// on fixe une valeur repère qui indique que le menu est fermé
 
    var menuOuvert = false
 
 
    // Chargement de la page en small devices
 
    initLoadSmall();
 
    // Corrections des comportements "anormaux" lors du resize de l'écran (pour rendre responsive en direct)
 
    $(window).resize(function () {
 
        if (window.matchMedia("(max-width: 850px)").matches) {
            $('nav, #titre1, .menuGauche, .liseret, section .titre, section #caroussel').css('transform', 'none');
            if (menuOuvert == false) {
                $('.menuGauche').hide();
                $('.liseret').css('border-bottom', '0');
            }
        }
 
        else {
            if (menuOuvert == false) {
                $('nav, #titre1, .menuGauche, .liseret, section .titre, section #caroussel').css('transform', 'translate(-260px)');
            }
        }
 
    });
 
 
 
    $('.liseret').on('click', function () {
 
        // Changement de l'icone avec les classes fontawesome - le changement de couleur se fait avec le CSS
 
        iconeMenu();
 
        // Affichage / disparition du menu en lui-même
 
        if (menuOuvert == false) {
            menuOpen();
 
        } else if (menuOuvert == true) {
            menuClose();
 
        };
 
    });

Je suis conscient que cela n'a pas de sens de faire d'un coup la barre vers la gauche et de l'autre la barre de menu en haut, mais j'aimerais vraiment arrivé au bout de mon idée.

Merci d'avance pour vos conseils