回答編集履歴

1

修正

2021/01/19 17:01

投稿

Jon_do
Jon_do

スコア1373

test CHANGED
@@ -1 +1,253 @@
1
1
  スライダーの背景色をcssで黒にしたら出来ます。
2
+
3
+ と思ったら出来ませんでした。
4
+
5
+ optionを色々と調べたんですが出来ませんでした。
6
+
7
+ 仕方がないのでcssAnimationをJavascriptで追加して対応しました。
8
+
9
+
10
+
11
+ ```html
12
+
13
+ <!DOCTYPE html>
14
+
15
+ <html lang="ja">
16
+
17
+
18
+
19
+ <head>
20
+
21
+ <meta charset="UTF-8">
22
+
23
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
24
+
25
+ <title>swiper(fade)</title>
26
+
27
+ <link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css">
28
+
29
+ <style>
30
+
31
+ .swiper-container {
32
+
33
+ width: 600px;
34
+
35
+ height: 400px;
36
+
37
+ text-align: center;
38
+
39
+ }
40
+
41
+
42
+
43
+ .fade {
44
+
45
+ width: 600px;
46
+
47
+ height: 400px;
48
+
49
+ background-color: black;
50
+
51
+ opacity: 0;
52
+
53
+ z-index: 1;
54
+
55
+ position: absolute;
56
+
57
+ top: 0;
58
+
59
+
60
+
61
+ }
62
+
63
+
64
+
65
+ .fadeOut {
66
+
67
+ animation-name: fadeOut;
68
+
69
+ animation-duration: 0.5s;
70
+
71
+ animation-delay: 4s;
72
+
73
+ animation-fill-mode: forwards;
74
+
75
+ }
76
+
77
+
78
+
79
+ .fadeIn {
80
+
81
+ animation-name: fadeIn;
82
+
83
+ animation-duration: 0.5s;
84
+
85
+ animation-delay: 1s;
86
+
87
+ animation-fill-mode: forwards;
88
+
89
+ }
90
+
91
+
92
+
93
+ @keyframes fadeOut {
94
+
95
+ 0% {
96
+
97
+ opacity: 0;
98
+
99
+
100
+
101
+ }
102
+
103
+
104
+
105
+ 100% {
106
+
107
+ opacity: 1;
108
+
109
+ }
110
+
111
+
112
+
113
+ }
114
+
115
+
116
+
117
+ @keyframes fadeIn {
118
+
119
+ 0% {
120
+
121
+ opacity: 1;
122
+
123
+
124
+
125
+ }
126
+
127
+
128
+
129
+ 100% {
130
+
131
+ opacity: 0;
132
+
133
+ }
134
+
135
+
136
+
137
+ }
138
+
139
+ </style>
140
+
141
+ </head>
142
+
143
+
144
+
145
+ <body>
146
+
147
+ <div class="swiper-container">
148
+
149
+ <!-- Additional required wrapper -->
150
+
151
+
152
+
153
+ <div class="swiper-wrapper">
154
+
155
+ <div class="fade fadeOut"></div>
156
+
157
+ <div class="swiper-slide">
158
+
159
+ <div class="slide-img"><img src="https://dummyimage.com/600x400/0009ff/fff&text=1" alt=""></div>
160
+
161
+ </div>
162
+
163
+ <div class="swiper-slide">
164
+
165
+ <div class="slide-img"><img src="https://dummyimage.com/600x400/0009ff/fff&text=2" alt=""></div>
166
+
167
+ </div>
168
+
169
+ <div class="swiper-slide">
170
+
171
+ <div class="slide-img"><img src="https://dummyimage.com/600x400/0009ff/fff&text=3" alt=""></div>
172
+
173
+ </div>
174
+
175
+ </div>
176
+
177
+ </div>
178
+
179
+ <script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
180
+
181
+ <script>
182
+
183
+
184
+
185
+ const SwiperStart = new Swiper('.swiper-container', {
186
+
187
+ loop: true,
188
+
189
+ effect: "fade",
190
+
191
+ autoplay: {
192
+
193
+ delay: 4000,
194
+
195
+ },
196
+
197
+ speed: 2000
198
+
199
+ })
200
+
201
+
202
+
203
+ const fadeItem = document.getElementsByClassName("fade");
204
+
205
+
206
+
207
+ fadeItem[0].addEventListener('animationend', () => {
208
+
209
+ const fade = document.getElementsByClassName("fade")[0];
210
+
211
+ if (fade.classList.contains("fadeOut")) {
212
+
213
+ fade.style.opacity = 1;
214
+
215
+ fade.classList.remove("fadeOut");
216
+
217
+ fade.classList.add("fadeIn")
218
+
219
+
220
+
221
+ } else {
222
+
223
+ fade.style.opacity = 0;
224
+
225
+ fade.classList.remove("fadeIn");
226
+
227
+ fade.classList.add("fadeOut")
228
+
229
+ }
230
+
231
+
232
+
233
+ });
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+ </script>
246
+
247
+ </body>
248
+
249
+
250
+
251
+ </html>
252
+
253
+ ```