前提
プログラミング歴:1週間
使用ツール:サクラエディタ
heroku上に表示する
実現したいこと
背景に設置している4枚の画像を時間で切り替えたい。
→背景画像はfixedを使いスクロールしても途切れない状態
→背景画像のサイズはpc画面ちょうど。
完成イメージとしては、下記の画像で表示している青空の背景画像を(現在は.bg_img で背景を表示)
10秒程度で、他の画像(.bg_img .src1内にあるURLのやつ)に変更可能にしたいです。
html,cssの構造?は背景画像の切り替えができれば変更しても構いません。
→cssのsample以下は透かしの背景色を調整しているので、そのまま機能を残したいです。
・背景画像の表示は
→透かしの下に置く
→1枚の画像で画面サイズにcoverする様に表示(norepeat)
→下にスクロールしても、背景が画像がちゃんと付いてくる(fixed)。
今の問題
追加
・背景画像が灰色になった
・コンテンツ(紫の透かし)が左寄りになり、サイトの1番下まで行かず途切れている。
・回答のコードを試しましたが、下記の様な状態になっています。
→切り替えの画像がテキストの上に来てしまう。
→背景画像の切り替えは紫の透かしの下で行いたい
→赤信号の様にrepeatせず、後ろの空の画像の様に1枚で画面をcoverできるようにしたい。
html
1</head> 2<body> 3 <div class="bg_img"> 4 <div class="sample"> 5 6 <div class="hat src1"></div> 7 <div class="hat src2"></div> 8 <div class="hat src3"></div> 9 <div class="hat src4"></div> 10 11 -テキスト・画像 12 13 </div> 14 </div> 15</body> 16
css
1* { 2 padding: 0; 3 margin: 0; 4} 5 6html, 7body { 8 width: 100%; 9 height:300%; 10} 11 12.bg_img { 13 background-image : url("doraemon_background_1.png"); 14 background-size: cover; 15 min-height: 100vh; 16 background-attachment: fixed; 17 overflow : hidden; 18} 19.bg_img .hat{ 20 position : absolute; 21 top : 0; 22 left : 0; 23 bottom : 0; 24 right : 0; 25 opacity : 0; 26 animation : bgAnime 40s infinite; 27} 28 29.bg_img .src1 { 30 background-image : url("doraemon_background_1.png"); /* 背景の画像を指定 */ 31} 32.bg_img .src2 { 33 background-image : url("doraemon_kabegami1.png"); /* 背景の画像を指定 */ 34 animation-delay : 10s; 35} 36.bg_img .src3 { 37 background-image : url("doraemon_background2.png"); /* 背景の画像を指定 */ 38 animation-delay : 20s; 39} 40.bg_img .src4 { 41 background-image : url("doraemon_kabegami1.png"); /* 背景の画像を指定 */ 42 animation-delay : 30s; 43} 44@keyframes bgAnime { 45 0% { opacity: 0; } 46 10% { opacity: 1; } 47 25% { opacity: 1; } 48 35% { opacity: 0; } 49 100% { opacity: 0; } 50} 51 52.sample { 53 background-color: rgba(255, 255, 255, 0.5); 54 height: 100%; 55 width: 50%; /* 透かしにする背景色の横の長さはここで調整 */ 56 margin: 0 auto; 57 animation: change-bgcolor 60s cubic-bezier(0, 1, 0, 1) infinite; 58} 59 60@keyframes change-bgcolor { 61 25% { 62 background-color: rgba(255, 255, 255, 0.5); 63 } 64 50% { 65 background-color: rgba(255, 0, 0, 0.5); 66 } 67 75% { 68 background-color: rgba(0, 255, 0, 0.5); 69 } 70 100% { 71 background-color: rgba(0, 0, 255, 0.5); 72 }
html
1</head> 以下の全文を念の為に記載します。 2<body> 3 4 5 <script> 6 MQTTconnect(); 7 </script> 8 <div class="bg_img"> 9 <div class="sample"> 10 11 <div class="hat src1"></div> 12 <div class="hat src2"></div> 13 <div class="hat src3"></div> 14 <div class="hat src4"></div> 15<h2> タイトル</h2> 16 17 <p> 18 現在の時刻: {{now}} 19 </p> 20 CloudMQTT 接続 Status: <div id="status">Connection Status: Not Connected</div> 21 <br> 22 23 24 <h2 id="example2"> </h2> 25 <figure> 26 <p><img id="a_signal" src="写真" WIDTH = "700px" HEIGHTl = "500px"></p> 27 </figure> 28 <br> 29 <h2 id="example2"> </h2> 30 <font size = "7" color="#F00">文字</font> 31 <br> 32 33 <p><a href="#example"><font size = "6">↓↓↓文字↓↓↓</font></a></p> 34 35 <p> 36 <div style="margin-bottom:1000px"></div><font size = "6" color="#000"></font> 37 </p> 38 39 40 41 42 <h2 id="example"> </h2> 43 文字:<p id="messages"></p> 44 <figure> 45 <img id="trafic_signal" src="写真" WIDTH = "700px" HEIGHTl = "500px"> 46 </figure> 47 <br> 48 49 <p> 50 <input type="button" value="文字" onclick="clickBtn("BLUE")" style="font-size:28px; color:#ffffff;background-color:#4EE27F;WIDTH:350px; HEIGHT:80px;"/> 51 <input type="button" value="文字" onclick="clickBtn("RED")" style="font-size:28px; color:#000000;background-color:#FF0000;WIDTH:350px; HEIGHT:80px;"/><br> 52 <input type="button" value="文字" onclick="clickBtn("YELLOW")" style="font-size:28px; color:#000000;background-color:#FFFF00;WIDTH:700px; HEIGHT:80px;"/> 53 <p><font size = "6">文字</font></p> 54 <input type="button" value="文字" onclick="clickBtn3("A")" style="font-size:24px; color:#ffffff;background-color:#000000;WIDTH:96px; HEIGHT:72px;"/> 55 <input type="button" value="文字" onclick="clickBtn3("B")" style="font-size:24px; color:#000000;background-color:#ffffff;WIDTH:96px; HEIGHT:72px;"/> 56 <input type="button" value="文字" onclick="clickBtn3("C")" style="font-size:24px; color:#ffffff;background-color:#000000;WIDTH:96px; HEIGHT:72px;"/> 57 <input type="button" value="文字" onclick="clickBtn3("D")" style="font-size:24px; color:#000000;background-color:#ffffff;WIDTH:96px; HEIGHT:72px;"/> 58 <input type="button" value="文字" onclick="clickBtn3("E")" style="font-size:24px; color:#ffffff;background-color:#000000;WIDTH:96px; HEIGHT:72px;"/> 59 <input type="button" value="文字" onclick="clickBtn3("F")" style="font-size:24px; color:#000000;background-color:#ffffff;WIDTH:96px; HEIGHT:72px;"/> 60 </p> 61 62 63 <p> 64 <div style="margin-bottom:2000px"></div> 65 </p> 66 67 68 69 70 71 <figure> 72 <legend> 文字 </legend> 73 <img id="c_signal" src="写真" WIDTH = "700px" HEIGHTl = "500px"> 74 </figure> 75 <br> 76 <input type="button" value="文字" onclick="clickBtn("RED")" style="font-size:28px; color:#000000;background-color:#FFFF00;WIDTH:700px; HEIGHT:80px;"/> 77 78 <p><a href="#example2"><font size = "6">↑↑↑一番上に戻る↑↑↑</font></a></p> 79 </div> 80 </div> 81
回答2件
あなたの回答
tips
プレビュー