###実現したいこと
AとBのメッセージを3秒ごとに交互に表示したいです。
Aを3回点滅させ、次にBを3回点滅、というのを3秒ごとに繰りかえす感じです。
###該当のソースコード
こちらのメッセージです。「is_open」の有無で表示の切り替えを考えています。
html
1<div class="messages"> 2 <p class="A animated flash infinite is_open">A</p> 3 <p class="B animated flash infinite">B</p> 4</div>
点滅もさせたいのでCSSがこちらになります。
CSS
1/* 2* 基本デザイン 3**************************/ 4.messages { 5 position: relative; 6} 7.A { 8 position: absolute; 9 color: red; 10} 11.B { 12 position: absolute; 13 color: blue; 14} 15p:not(.is_open) { 16 display: none; 17} 18 19/* 20* アニメーション 21**************************/ 22.animated { 23 -webkit-animation-duration: 3s; 24 animation-duration:3s; 25} 26.flash { 27 -webkit-animation-name: flash; 28 animation-name: flash; 29} 30.infinite { 31 -webkit-animation-iteration-count: infinite; 32 animation-iteration-count: infinite; 33} 34 35@-webkit-keyframes flash { 36 from, 37 50%, 38 to { 39 opacity: 1; 40 } 41 42 25%, 43 75% { 44 opacity: 0; 45 } 46} 47 48@keyframes flash { 49 from, 50 50%, 51 to { 52 opacity: 1; 53 } 54 55 25%, 56 75% { 57 opacity: 0; 58 } 59} 60 61
###試したこと
setIntervalを使い、クラスのある方からクラスをとって、ない方にクラスをつける。という処理の繰り返しによって実現しようと思ったのですが、これですと、AとBが重なってしまいました。
どうすれば、「A → A → A → B → B → B → A → A → A...」のような点滅を繰り返すことができるでしょうか?
jquery
1$(function(){ 2 setInterval(function(){ 3 $('.messages > p.is_open').removeClass('is_open'); 4 $('.messages > p:not(.is_open)').addClass('is_open'); 5 },3000); 6});
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/16 08:40
2019/06/16 11:02
2019/06/16 21:11