回答編集履歴
1
調整
answer
CHANGED
|
@@ -1,2 +1,41 @@
|
|
|
1
1
|
ポイントが良くわからないのですが、特定の範囲内でクラスを定期的にローテーションするんですよね?
|
|
2
|
-
クラスの付替えのタイミングをずらしたいのか、ついたあとの挙動のタイミングをずらしたいのか、希望がどこなのかがよくわかりません。キーフレームアニメーションの場合例えば0%から30%まで要素の値をキープすればdelayできませんか?
|
|
2
|
+
クラスの付替えのタイミングをずらしたいのか、ついたあとの挙動のタイミングをずらしたいのか、希望がどこなのかがよくわかりません。キーフレームアニメーションの場合例えば0%から30%まで要素の値をキープすればdelayできませんか?
|
|
3
|
+
|
|
4
|
+
的はずれな回答でしたら申し訳ないですが一応サンプル
|
|
5
|
+
```html
|
|
6
|
+
<style>
|
|
7
|
+
.fuga{
|
|
8
|
+
width:100px;
|
|
9
|
+
height:50px;
|
|
10
|
+
margin:10px;
|
|
11
|
+
background-Color:yellow;
|
|
12
|
+
}
|
|
13
|
+
.piyo{
|
|
14
|
+
animation: prog 1s normal;
|
|
15
|
+
background-Color:lime;
|
|
16
|
+
}
|
|
17
|
+
@keyframes prog {
|
|
18
|
+
0% { width: 100px }
|
|
19
|
+
30% { width: 100px }
|
|
20
|
+
100% { width: 300px}
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
23
|
+
<script>
|
|
24
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
|
25
|
+
setInterval((function loop(){
|
|
26
|
+
const cnt=document.querySelectorAll(`.fuga`).length;
|
|
27
|
+
let idx=[...document.querySelectorAll(`.fuga`)].indexOf(document.querySelector(`.piyo`))+2;
|
|
28
|
+
if(idx>cnt) idx=1;
|
|
29
|
+
console.log(idx);
|
|
30
|
+
if(document.querySelector(`.piyo`)) document.querySelector(`.piyo`).classList.remove('piyo');
|
|
31
|
+
document.querySelector(`:nth-child(${idx} of .fuga)`).classList.add('piyo');
|
|
32
|
+
return loop;
|
|
33
|
+
})(),1000);
|
|
34
|
+
});
|
|
35
|
+
</script>
|
|
36
|
+
<div id="hoge">
|
|
37
|
+
<div class="fuga">1</div>
|
|
38
|
+
<div class="fuga">2</div>
|
|
39
|
+
<div class="fuga">3</div>
|
|
40
|
+
</div>
|
|
41
|
+
```
|