質問編集履歴

2

タイトルの修正

2019/04/18 15:30

投稿

YutaOkuma
YutaOkuma

スコア15

test CHANGED
@@ -1 +1 @@
1
- ウェブサイトのトップページでフルスクリーンのスライドショーを作成たい!
1
+ CSS作成したフルスクリーンのスライドショーに白いフリッカーがはいってまう…。
test CHANGED
File without changes

1

CSSアニメーションでトランジション前に白いフリッカーが入ってしまったコードを記述しました。

2019/04/18 15:30

投稿

YutaOkuma
YutaOkuma

スコア15

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  CSSアニメーションを使って画像と画像がクロスフェードするフルスクリーンのスライドショーを作ってみたのですが、
4
4
 
5
- 画像のトランジションの際に一瞬白いフリッカーが入ってしまいました。
5
+ **画像のトランジションの際に一瞬白いフリッカー**が入ってしまいました。
6
6
 
7
7
  現在試行錯誤しておりますが、なかなかうまく行きません。
8
8
 
@@ -10,76 +10,106 @@
10
10
 
11
11
 
12
12
 
13
- CodePenのサイトで見つけたJavaScirptを使った方法を自分なり試しましたが、うまく行きません。
14
13
 
15
- 一応その時のコードを載せておきます!
16
14
 
15
+ ```html
16
+
17
+ <!DOCTYPE html>
18
+
19
+ <html lang="en">
20
+
21
+ <head>
22
+
23
+ <meta charset="utf-8">
24
+
25
+ <link rel="stylesheet" href="css/style.css">
26
+
27
+ <title>Slideshow</title>
28
+
17
- ぜひどなたかよろしくお願いします!!
29
+ </head>
30
+
31
+ <body>
32
+
33
+ <div class="slideshow">
34
+
35
+ <div class="content">
36
+
37
+ <h1>Creativity. Passion. Motivation.</h1>
38
+
39
+ <h3>Make even the ordinary possible.</h3>
40
+
41
+ </div>
42
+
43
+ </div>
44
+
45
+ </body>
46
+
47
+ </html>
48
+
49
+
50
+
51
+ ```
18
52
 
19
53
 
20
54
 
21
55
  ```css
22
56
 
23
- html {
57
+ body {
24
58
 
25
59
  margin: 0;
26
60
 
61
+ padding: 0;
62
+
63
+ }
64
+
65
+
66
+
67
+ .slideshow {
68
+
69
+ height: 100vh;
70
+
71
+ weight: 100%;
72
+
73
+ background-image: url('../images/1.jpg');
74
+
27
75
  background-size: cover;
28
76
 
29
- background: url('../1.jpg') no-repeat center center fixed;
77
+ animation: slide 24s infinite;
30
78
 
31
- background-blend-mode: darken;
79
+ }
32
80
 
33
- // blend mode optional at this stage; will be used more in the next demo.
34
81
 
82
+
83
+ @keyframes slide {
84
+
85
+ 25% {
86
+
87
+ background-image: url('../images/2.jpg');
88
+
35
- transition: 3s;
89
+ background-size: cover;
90
+
91
+ }
92
+
93
+
94
+
95
+ 50% {
96
+
97
+ background-image: url('../images/3.jpg');
98
+
99
+ background-size: cover;
100
+
101
+ }
102
+
103
+
104
+
105
+ 75% {
106
+
107
+ background-image: url('../images/4.jpg');
108
+
109
+ background-size: cover;
110
+
111
+ }
36
112
 
37
113
  }
38
114
 
39
115
  ```
40
-
41
-
42
-
43
- ```js
44
-
45
- var bgImageArray = ["1.jpg", "2.jpg", "3.jpg", "4.jpg"],
46
-
47
- base = '../',
48
-
49
- secs = 4;
50
-
51
- bgImageArray.forEach(function(img){
52
-
53
- new Image().src = base + img;
54
-
55
- // caches images, avoiding white flash between background replacements
56
-
57
- });
58
-
59
-
60
-
61
- function backgroundSequence() {
62
-
63
- window.clearTimeout();
64
-
65
- var k = 0;
66
-
67
- for (i = 0; i < bgImageArray.length; i++) {
68
-
69
- setTimeout(function(){
70
-
71
- document.documentElement.style.background = "url(" + base + bgImageArray[k] + ") no-repeat center center fixed";
72
-
73
- document.documentElement.style.backgroundSize ="cover";
74
-
75
- if ((k + 1) === bgImageArray.length) { setTimeout(function() { backgroundSequence() }, (secs * 1000))} else { k++; }
76
-
77
- }, (secs * 1000) * i)
78
-
79
- }
80
-
81
- }
82
-
83
- backgroundSequence();
84
-
85
- ```