質問編集履歴

3

追加

2020/05/28 01:26

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -51,6 +51,66 @@
51
51
  });
52
52
 
53
53
  ```
54
+
55
+ ```JQUERY
56
+
57
+ $(function () {
58
+
59
+ $('.slideshow').each(function () {
60
+
61
+ let $slides = $(this).find('img'),
62
+
63
+ slideCount = $slides.length,
64
+
65
+ currentIndex = 0;
66
+
67
+ $slides.eq(currentIndex).fadeIn();
68
+
69
+ timer = setInterval(showNextSlide, 1000);
70
+
71
+ function showNextSlide () {
72
+
73
+ let nextIndex = (currentIndex + 1) % slideCount;
74
+
75
+ $slides.eq(currentIndex).fadeOut();
76
+
77
+ $slides.eq(nextIndex).fadeIn();
78
+
79
+ currentIndex = nextIndex;
80
+
81
+ }
82
+
83
+ function stop() {
84
+
85
+ clearInterval(timer);
86
+
87
+ timer = null;
88
+
89
+ }
90
+
91
+ $('img').on('click', function() {
92
+
93
+ if (timer != null) {
94
+
95
+ stop();
96
+
97
+ } else {
98
+
99
+ setInterval(showNextSlide, 1000);
100
+
101
+ timer = 1;
102
+
103
+ }
104
+
105
+ });
106
+
107
+ });
108
+
109
+ });
110
+
111
+ ```
112
+
113
+ 2番目のJQUERYのようにすれば、再開はできたのですが、2度目以降ののストップと再開ができません。
54
114
 
55
115
  ```html
56
116
 

2

更新

2020/05/28 01:26

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -36,11 +36,13 @@
36
36
 
37
37
  if (timer != null) {
38
38
 
39
- timer = clearInterval(timer);
39
+ clearInterval(timer);
40
+
41
+ timer = null;
40
42
 
41
43
  } else {
42
44
 
43
- timer = setInterval(showNextSlide, 1000);
45
+ setInterval(showNextSlide, 1000);
44
46
 
45
47
  }
46
48
 

1

更新

2020/05/28 01:08

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -106,6 +106,4 @@
106
106
 
107
107
  </html>
108
108
 
109
-
110
-
111
109
  ```