前提・実現したいこと
四角形の黒い図形が回転するローダーを組んでいるんですが、別のページからトップページに飛ぶ時も毎回ローダーが出てきてしまいます。ページ遷移するときはローダーが出てこないようにする方法はないでしょうか。
該当のソースコード
HTML
1 <div id="loader" class="loader active"> 2 <div class="loader-item"></div> 3 </div>
SCSS
1@mixin animation ( 2 $name, 3 $duration: 1s, 4 $delay: 0s, 5 $iteration-count: 1, 6 $timing-function: ease, 7 $direction: normal, 8 $fill-mode: forwards 9) { 10 animation: { 11 name: $name; 12 duration: $duration; 13 delay: $delay; 14 iteration-count: $iteration-count; 15 timing-function: $timing-function; 16 direction: $direction; 17 fill-mode: $fill-mode; 18 } 19} 20 21.loader { 22 position: fixed; 23 top: 0; 24 left: 0; 25 width: 100%; 26 height: 100%; 27 font-size: 30px; 28 background: white; 29 z-index: 100; 30 opacity: 0; 31 transition: .5s; 32 perspective: 120px; 33 perspective-origin: center center; 34 display: flex; 35 justify-content: center; 36 align-items: center; 37 visibility: hidden; 38} 39 40.loader.active { 41 opacity: 1; 42 visibility: visible; 43} 44 45.loader.active .loader-item { 46 width: 50px; 47 height: 50px; 48 background:rgba(0, 0, 0); 49 @include animation ( 50 $name: loaderSquare, 51 $duration: 1s, 52 $iteration-count: infinite, 53 $timing-function: ease-in-out 54 ); 55} 56 57@keyframes loaderSquare { 58 0% { 59 transform: rotate(0); 60 } 61 50% { 62 transform: rotateX(-180deg); 63 } 64 100% { 65 transform: rotateX(-180deg) rotateY(-180deg); 66 } 67}
javaScript
1 function loaderAnimation () { 2 const loaderElement = document.querySelector('#loader'); 3 loaderElement.classList.remove('active'); 4} 5 6window.addEventListener('DOMContentLoaded', function(){ 7 setTimeout(loaderAnimation, 2000) 8}, 9{once: true});
試したこと
once: trueを使いましたが、何も変わりませんでした。
補足情報(FW/ツールのバージョンなど)
Macbook Air M1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/29 03:59 編集
2022/07/02 07:54