スマホメニューを作成しています。
keyframeで表示非表示を指定しているのですが、menu_offの指定がページ読み込み時に動作してしまうため、一瞬メニューが画面に表示されてしまいます。
解決策がありましたらご教示いただければと思います。
何卒よろしくお願いいたします。
html
1<body> 2 <div class="button_menu"></div> 3 <section class="menu_sp"> 4 <div>コンテンツ</div> 5 </section> 6</body>
css
1body { 2 width:100vw; 3 min-height:100vh; 4 background:gray; 5} 6.menu_sp { 7 width: 100vw; 8 height: 100vh; 9 background: rgba(255,255,255,.97) ; 10 display: -webkit-flex; display: flex; 11 -webkit-flex-wrap: wrap; flex-wrap: wrap; 12 -webkit-flex-direction: column; flex-direction: column; 13 -webkit-align-items: center; align-items: center; 14 -webkit-justify-content: center; justify-content: center; 15 position: fixed; 16 top: 0; 17 left: 0; 18 z-index: -99; 19 animation: menu_off .5s ease forwards; 20} 21.menu_on .menu_sp { 22 animation: menu_on .5s ease forwards; 23} 24@keyframes menu_on { 25 0% { 26 opacity: 0; 27 z-index: 99; 28 } 29 100% { 30 opacity: 1; 31 z-index: 99; 32 } 33} 34@keyframes menu_off { 35 0% { 36 opacity: 1; 37 z-index: 99; 38 } 39 99% { 40 z-index: 99; 41 opacity: 0; 42 } 43 100% { 44 z-index: -99; 45 opacity: 0; 46 } 47} 48.button_menu { 49 cursor: pointer; 50 width: 20px; 51 height: 20px; 52 background: blue; 53 position: absolute; 54 top: 10px; 55 right: 10px; 56}
js
1 <script> 2 $(".button_menu").click( 3 function () { 4 $("body").toggleClass("menu_on"); 5 } 6 ); 7 $(".menu_sp").click( 8 function () { 9 $("body").toggleClass("menu_on"); 10 } 11 ); 12 </script>
回答1件
あなたの回答
tips
プレビュー