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

質問編集履歴

2

タイトルの修正

2019/04/18 15:30

投稿

YutaOkuma
YutaOkuma

スコア15

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

1

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

2019/04/18 15:30

投稿

YutaOkuma
YutaOkuma

スコア15

title CHANGED
File without changes
body CHANGED
@@ -1,43 +1,58 @@
1
1
  ###ウェブサイトでフルスクリーンのクロスフェードを使ったスライドショーを作成したい。
2
2
  CSSアニメーションを使って画像と画像がクロスフェードするフルスクリーンのスライドショーを作ってみたのですが、
3
- 画像のトランジションの際に一瞬白いフリッカーが入ってしまいました。
3
+ **画像のトランジションの際に一瞬白いフリッカー**が入ってしまいました。
4
4
  現在試行錯誤しておりますが、なかなかうまく行きません。
5
5
  CSSじゃなくてもJavaScriptを使っても良いので、どなたかクロスフェードのスライドショーの作り方を教えていただける方はいませんでしょうか?
6
6
 
7
- CodePenのサイトで見つけたJavaScirptを使った方法を自分なり試しましたが、うまく行きません。
8
- 一応その時のコードを載せておきます!
9
- ぜひどなたかよろしくお願いします!!
10
7
 
8
+ ```html
9
+ <!DOCTYPE html>
10
+ <html lang="en">
11
+ <head>
12
+ <meta charset="utf-8">
13
+ <link rel="stylesheet" href="css/style.css">
14
+ <title>Slideshow</title>
15
+ </head>
16
+ <body>
17
+ <div class="slideshow">
18
+ <div class="content">
19
+ <h1>Creativity. Passion. Motivation.</h1>
20
+ <h3>Make even the ordinary possible.</h3>
21
+ </div>
22
+ </div>
23
+ </body>
24
+ </html>
25
+
26
+ ```
27
+
11
28
  ```css
12
- html {
29
+ body {
13
30
  margin: 0;
31
+ padding: 0;
32
+ }
33
+
34
+ .slideshow {
35
+ height: 100vh;
36
+ weight: 100%;
37
+ background-image: url('../images/1.jpg');
14
38
  background-size: cover;
15
- background: url('../1.jpg') no-repeat center center fixed;
16
- background-blend-mode: darken;
39
+ animation: slide 24s infinite;
17
- // blend mode optional at this stage; will be used more in the next demo.
18
- transition: 3s;
19
40
  }
20
- ```
21
41
 
42
+ @keyframes slide {
22
- ```js
43
+ 25% {
23
- var bgImageArray = ["1.jpg", "2.jpg", "3.jpg", "4.jpg"],
24
- base = '../',
44
+ background-image: url('../images/2.jpg');
25
- secs = 4;
26
- bgImageArray.forEach(function(img){
27
- new Image().src = base + img;
45
+ background-size: cover;
28
- // caches images, avoiding white flash between background replacements
29
- });
46
+ }
30
47
 
48
+ 50% {
49
+ background-image: url('../images/3.jpg');
31
- function backgroundSequence() {
50
+ background-size: cover;
32
- window.clearTimeout();
33
- var k = 0;
34
- for (i = 0; i < bgImageArray.length; i++) {
35
- setTimeout(function(){
36
- document.documentElement.style.background = "url(" + base + bgImageArray[k] + ") no-repeat center center fixed";
37
- document.documentElement.style.backgroundSize ="cover";
38
- if ((k + 1) === bgImageArray.length) { setTimeout(function() { backgroundSequence() }, (secs * 1000))} else { k++; }
39
- }, (secs * 1000) * i)
40
- }
51
+ }
52
+
53
+ 75% {
54
+ background-image: url('../images/4.jpg');
55
+ background-size: cover;
56
+ }
41
57
  }
42
- backgroundSequence();
43
58
  ```