前提・実現したいこと
「Loading...」
「Starting...」
「Let's Go!」
と3つの文字それぞれを2秒で切り替えたい
該当のソースコード
html
1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <meta charset="UTF-8"> 5 <title>loading</title> 6 <link rel="stylesheet" href="style1.css"> 7</head> 8<body> 9 <div class="loading"> 10 <P class="tests"> 11 <span>Loading...</span> 12 </P> 13 </div> 14</body> 15</html>
css
1body{ 2 margin:0; 3 padding: 0; 4 background: #34495e; 5 height:100vh; 6 display:flex; 7 align-items:center; 8 justify-content:center; 9 font-family:"montserrat",sans-serif; 10} 11 12.loading{ 13 width:200px; 14 height:200px; 15 box-sizing:border-box; 16 border-radius:50%; 17 border-top:10px solid #e74c3c; 18 position: relative; 19 animation:a1 2s linear infinite; 20} 21.loading::before,.loading::after{ 22 content:""; 23 width:200px; 24 height:200px; 25 position:absolute; 26 left:0; 27 top:-10px; 28 box-sizing:border-box; 29 border-radius: 50%; 30} 31.loading::before{ 32 border-top:10px solid #e67e22; 33 transform:rotate(120deg); 34} 35.loading::after{ 36 border-top:10px solid #3498db; 37 transform:rotate(240deg); 38} 39.loading span{ 40 position:absolute; 41 width:200px; 42 height:200px; 43 color:#fff; 44 text-align:center; 45 line-height:200px; 46 animation:a2 2s linear infinite; 47} 48 49@keyframes a1{ 50 to{ 51 transform:rotate(360deg); 52 } 53} 54 55@keyframes a2{ 56 to{ 57 transform:rotate(-360deg); 58 } 59}
このコードの「Loading...」の部分を2秒後に「Starting...」に切り替る。
その2秒後、「Let's Go!」に切り替える。
試したこと
html
1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <meta charset="UTF-8"> 5 <title>loading</title> 6 <link rel="stylesheet" href="style1.css"> 7</head> 8<body> 9 <div class="loading"> 10 <p class="texts"> 11 <span>Loading...</span> 12 <span>Starting...</span> 13 <span>Let's Go!</span> 14 </p> 15 </div> 16</body> 17</html>
css
1body{ 2 margin:0; 3 padding: 0; 4 background: #34495e; 5 height:100vh; 6 display:flex; 7 align-items:center; 8 justify-content:center; 9 font-family:"montserrat",sans-serif; 10} 11 12.loading{ 13 width:200px; 14 height:200px; 15 box-sizing:border-box; 16 border-radius:50%; 17 border-top:10px solid #e74c3c; 18 position: relative; 19 animation:a1 2s linear infinite; 20} 21.loading::before,.loading::after{ 22 content:""; 23 width:200px; 24 height:200px; 25 position:absolute; 26 left:0; 27 top:-10px; 28 box-sizing:border-box; 29 border-radius: 50%; 30} 31.loading::before{ 32 border-top:10px solid #e67e22; 33 transform:rotate(120deg); 34} 35.loading::after{ 36 border-top:10px solid #3498db; 37 transform:rotate(240deg); 38} 39.loading span{ 40 position:absolute; 41 width:200px; 42 height:200px; 43 color:#fff; 44 text-align:center; 45 line-height:200px; 46 animation:a2 2s linear infinite; 47} 48 49@keyframes a1{ 50 to{ 51 transform:rotate(360deg); 52 } 53} 54 55@keyframes a2{ 56 to{ 57 transform:rotate(-360deg); 58 } 59} 60.texts{ 61 width: 5.5em; 62 height: 1.5em; 63 text-align: center; 64 overflow-y: hidden; 65} 66.texts span{ 67 position: relative; 68 display: inline-block; 69 width: 100%; 70 height: 100%; 71} 72 73/* アニメーション */ 74.texts span{ 75 animation: ShiftText 10s linear infinite; 76} 77 78@keyframes ShiftText{ 79 0%{ 80 opacity: 0; 81 } 82 83 1%,25%{ 84 top: 0; 85 opacity: 1; 86 } 87 88 26%,50%{ 89 top: -1.5em; 90 } 91 92 51%,75%{ 93 top: -3em; 94 } 95 96 76%,100%{ 97 top: -4.5em; 98 } 99}
素人ながらネットからの引用なので、色々と変ですがこれが自分の限界です。
#起きている問題点
「Loading...」に他の2つの文字が重なってしまい、文字が切り替えられないことです。
補足情報(FW/ツールのバージョンなど)
OS: Windows 10 Home
ブラウザ: Google Chrome(Version 79.0.3945.130 (Official Build) (64-bit))
を使用しています。
今起きている問題はなにでしょうか。
あと実際のloadingをとりたい訳じゃないということですよね。
アドバイスをありがとうございます。
「loadingをとる」とはどういう意味でしょうか?
私の理解力が乏しいだけに迷惑をお掛けしてしまい申し訳ありません。
「実際にページの読み込み状態をとるわけではなく」ということです。
読み込み状態に関わらず2秒で切り替えると
はい。
読み込み状態に関わらず2秒で切り替えるということです。
ご厚意にありがとうございます。
JavaScriptでやったほうが簡単に実装できそうですけどCSSだけでやりたいということですよね?
ありがとうございます。
JSの方が簡単でしたらJSでも大丈夫ですよ。