teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

typo

2019/04/05 07:55

投稿

yambejp
yambejp

スコア117946

answer CHANGED
@@ -1,6 +1,6 @@
1
1
  ```javascript
2
2
  <style>
3
- .hoge{height:100px;width;100px;padding:3px;}
3
+ .hoge{height:100px;width:100px;padding:3px;}
4
4
  .hoge.active{border:solid 3px red;padding:0px}
5
5
  </style>
6
6
  <script>

1

hover

2019/04/05 07:55

投稿

yambejp
yambejp

スコア117946

answer CHANGED
@@ -16,4 +16,34 @@
16
16
  <div class="hoge active">ここに中身</div>
17
17
  <div class="hoge">ここに中身</div>
18
18
  <div class="hoge">ここに中身</div>
19
+ ```
20
+
21
+ # hover対応
22
+ ```javascript
23
+ <style>
24
+ .hoge{height:100px;width:100px;padding:3px;}
25
+ .hoge.active{border:solid 3px red;padding:0px}
26
+ </style>
27
+ <script>
28
+ var timerId;
29
+ var idx=0;
30
+ $(function(){
31
+ $('.hoge').on('mouseover',function(){
32
+ clearInterval(timerId);
33
+ $('.hoge').removeClass('active');
34
+ $(this).addClass('active');
35
+ }).on('mouseout',function(){
36
+ timerId=setInterval(function(){
37
+ idx++;
38
+ idx%=$('.hoge').length;
39
+ $('.hoge').removeClass('active').eq(idx).addClass('active');
40
+ },1000);
41
+ idx=$('.hoge').index(this);
42
+ }).eq(0).trigger('mouseout');
43
+ });
44
+ </script>
45
+ <div class="hoge active">ここに中身</div>
46
+ <div class="hoge">ここに中身</div>
47
+ <div class="hoge">ここに中身</div>
48
+ <div class="hoge">ここに中身</div>
19
49
  ```