質問編集履歴
3
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,6 +25,36 @@
|
|
25
25
|
});
|
26
26
|
});
|
27
27
|
```
|
28
|
+
```JQUERY
|
29
|
+
$(function () {
|
30
|
+
$('.slideshow').each(function () {
|
31
|
+
let $slides = $(this).find('img'),
|
32
|
+
slideCount = $slides.length,
|
33
|
+
currentIndex = 0;
|
34
|
+
$slides.eq(currentIndex).fadeIn();
|
35
|
+
timer = setInterval(showNextSlide, 1000);
|
36
|
+
function showNextSlide () {
|
37
|
+
let nextIndex = (currentIndex + 1) % slideCount;
|
38
|
+
$slides.eq(currentIndex).fadeOut();
|
39
|
+
$slides.eq(nextIndex).fadeIn();
|
40
|
+
currentIndex = nextIndex;
|
41
|
+
}
|
42
|
+
function stop() {
|
43
|
+
clearInterval(timer);
|
44
|
+
timer = null;
|
45
|
+
}
|
46
|
+
$('img').on('click', function() {
|
47
|
+
if (timer != null) {
|
48
|
+
stop();
|
49
|
+
} else {
|
50
|
+
setInterval(showNextSlide, 1000);
|
51
|
+
timer = 1;
|
52
|
+
}
|
53
|
+
});
|
54
|
+
});
|
55
|
+
});
|
56
|
+
```
|
57
|
+
2番目のJQUERYのようにすれば、再開はできたのですが、2度目以降ののストップと再開ができません。
|
28
58
|
```html
|
29
59
|
<!DOCTYPE html>
|
30
60
|
<html class="no-js" lang="ja">
|
2
更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,9 +17,10 @@
|
|
17
17
|
});
|
18
18
|
$('img').on('click', function() {
|
19
19
|
if (timer != null) {
|
20
|
-
|
20
|
+
clearInterval(timer);
|
21
|
+
timer = null;
|
21
22
|
} else {
|
22
|
-
|
23
|
+
setInterval(showNextSlide, 1000);
|
23
24
|
}
|
24
25
|
});
|
25
26
|
});
|
1
更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -52,5 +52,4 @@
|
|
52
52
|
|
53
53
|
</body>
|
54
54
|
</html>
|
55
|
-
|
56
55
|
```
|