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

質問編集履歴

1

コードを追加しました

2020/06/13 08:09

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -3,5 +3,42 @@
3
3
  こちらが自分のコードです。
4
4
  https://jsfiddle.net/t0hfxkq3/3/
5
5
 
6
+ ```HTML
7
+ <img id="slider" width="200" height="200" alt="slide">
8
+ ```
9
+
10
+ ```CSS
11
+ #slider {
12
+ opacity: 1;
13
+ transition: opacity 1s;
14
+ }
15
+
16
+ #slider.fadeOut {
17
+ opacity: 0;
18
+ }
19
+ ```
20
+
21
+ ```javascript
22
+ var imgArray = [
23
+ 'https://images.unsplash.com/photo-1521673461164-de300ebcfb17?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60',
24
+ 'https://images.unsplash.com/photo-1497993950456-cdb57afd1cf1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60',
25
+ 'https://images.unsplash.com/photo-1530281700549-e82e7bf110d6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60'],
26
+ curIndex = 0;
27
+ imgDuration = 3000;
28
+
29
+ function slideShow() {
30
+ document.getElementById('slider').className += "fadeOut";
31
+ setTimeout(function() {
32
+ document.getElementById('slider').src = imgArray[curIndex];
33
+ document.getElementById('slider').className = "";
34
+ },1000);
35
+ curIndex++;
36
+ if (curIndex == imgArray.length) { curIndex = 0; }
37
+ setTimeout(slideShow, imgDuration);
38
+ }
39
+ slideShow();
40
+ ```
41
+
42
+
6
43
  スライドショーを作るのにはこのウェブページの二つ目のコードを参考にしました。
7
44
  https://stackoverflow.com/questions/25347946/add-fade-effect-in-slideshow-javascript