😆Multiple image cross fading in CSS - without (java) khá đẹp script (ok)

https://stackoverflow.com/questions/14313825/multiple-image-cross-fading-in-css-without-java-script

Example 1

C:\xampp82\htdocs\html\1.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="1.css">
</head>
<body>
  <div class="App">
    <img src="https://picsum.photos/id/1011/300/200" class="image4">
    <img src="https://picsum.photos/id/1016/300/200" class="image3">
    <img src="https://picsum.photos/id/1019/300/200" class="image2">
    <img src="https://picsum.photos/id/1018/300/200" class="image1">
  </div>
</body>
</html>

C:\xampp82\htdocs\html\1.scss

@keyframes cf4FadeInOut {
  40%,
  60% {
    opacity: 0;
  }
}
.App {
  display: grid;
  width: max-content;
  margin: auto;
}
.App img {
  grid-row: 1;
  grid-column: 1;
  animation-name: cf4FadeInOut;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-duration: 20s;
}
.App img:nth-of-type(1) {
  animation-delay: -15s;
}
.App img:nth-of-type(2) {
  animation-delay: -10s;
}
.App img:nth-of-type(3) {
  animation-delay: -5s;
}

Example 2

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="1.css">
</head>
<body>
  <div id="crossfade">
    <img src="https://loremflickr.com/g/1920/1080/paris" alt="Image 1">
    <img src="https://loremflickr.com/g/1920/1080/vietnam" alt="Image 2">
    <img src="https://loremflickr.com/g/1920/1080/japan" alt="Image 3">
    <img src="https://loremflickr.com/g/1920/1080/korea" alt="Image 1">
    <img src="https://loremflickr.com/g/1920/1080/rio" alt="Image 1">
  </div>
</body>
</html>
#crossfade > img { 
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    color: transparent;
    opacity: 0;
    z-index: 0;
    -webkit-backface-visibility: hidden;
    -webkit-animation: imageAnimation 30s linear infinite 0s;
    -moz-animation: imageAnimation 30s linear infinite 0s;
    -o-animation: imageAnimation 30s linear infinite 0s;
    -ms-animation: imageAnimation 30s linear infinite 0s;
    animation: imageAnimation 30s linear infinite 0s; 
}

#crossfade > img:nth-child(2)  {
    -webkit-animation-delay: 6s;
    -moz-animation-delay: 6s;
    -o-animation-delay: 6s;
    -ms-animation-delay: 6s;
    animation-delay: 6s; 
}
#crossfade > img:nth-child(3) {
    -webkit-animation-delay: 12s;
    -moz-animation-delay: 12s;
    -o-animation-delay: 12s;
    -ms-animation-delay: 12s;
    animation-delay: 12s; 
}
#crossfade > img:nth-child(4) {
    -webkit-animation-delay: 18s;
    -moz-animation-delay: 18s;
    -o-animation-delay: 18s;
    -ms-animation-delay: 18s;
    animation-delay: 18s; 
}
#crossfade > img:nth-child(5) {
    -webkit-animation-delay: 24s;
    -moz-animation-delay: 24s;
    -o-animation-delay: 24s;
    -ms-animation-delay: 24s;
    animation-delay: 24s; 
}

@-webkit-keyframes imageAnimation { 
    0% { opacity: 0;
    -webkit-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -webkit-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

@-moz-keyframes imageAnimation { 
    0% { opacity: 0;
    -moz-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -moz-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

@-o-keyframes imageAnimation { 
    0% { opacity: 0;
    -o-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -o-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

@-ms-keyframes imageAnimation { 
    0% { opacity: 0;
    -ms-animation-timing-function: ease-in; }
    8% { opacity: 1;
         -ms-animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

@keyframes imageAnimation { 
    0% { opacity: 0;
    animation-timing-function: ease-in; }
    8% { opacity: 1;
         animation-timing-function: ease-out; }
    17% { opacity: 1 }
    25% { opacity: 0 }
    100% { opacity: 0 }
}

Example 3

C:\xampp82\htdocs\html\1.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="1.css">
</head>
<body>
  <div id="home" class="panel">
    <div class="inner">
      <div id="backgroundchange">
        <div class="backgroundimg" id="back1"></div>
        <div class="backgroundimg" id="back2"></div>
        <div class="backgroundimg" id="back3"></div>
        <div class="backgroundimg" id="back4"></div>
        <div class="backgroundimg" id="back5"></div>
      </div>
    </div>
  </div>
</body>
</html>

C:\xampp82\htdocs\html\1.scss

html,
body {
  height: 100%;
  margin: 0;
}
.panel {
  font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
  color: white;
  height: 100%;
  min-width: 100%;
  text-align: center;
  display: table;
  margin: 0;
  background: #1c1c1c;
  padding: 0 0;
}
.panel .inner {
  display: table-cell;
  vertical-align: middle;
}
.backgroundimg {
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
}
#back1 {
  background: url("https://loremflickr.com/g/500/700/paris") no-repeat center
    fixed;
}
#back2 {
  background: url("https://loremflickr.com/g/500/600/paris") no-repeat center
    fixed;
}
#back3 {
  background: url("https://loremflickr.com/g/500/500/paris") no-repeat center
    fixed;
}
#back4 {
  background: url("https://loremflickr.com/g/500/800/paris") no-repeat center
    fixed;
}
#back5 {
  background: url("https://loremflickr.com/g/500/900/paris") no-repeat center
    fixed;
}
@keyframes backgroundchangeFadeInOut {
  0% {
    opacity: 1;
  }
  17% {
    opacity: 1;
  }
  25% {
    opacity: 0;
  }
  92% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
@-webkit-keyframes backgroundchangeFadeInOut {
  0% {
    opacity: 1;
  }
  17% {
    opacity: 1;
  }
  25% {
    opacity: 0;
  }
  92% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
#backgroundchange div:nth-of-type(1) {
  animation-delay: 8s;
  -webkit-animation-delay: 8s;
}
#backgroundchange div:nth-of-type(2) {
  animation-delay: 6s;
  -webkit-animation-delay: 6s;
}
#backgroundchange div:nth-of-type(3) {
  animation-delay: 4s;
  -webkit-animation-delay: 4s;
}
#backgroundchange div:nth-of-type(4) {
  animation-delay: 2s;
  -webkit-animation-delay: 2s;
}
#backgroundchange div:nth-of-type(5) {
  animation-delay: 0;
  -webkit-animation-delay: 0;
}
#backgroundchange div {
  animation-name: backgroundchangeFadeInOut;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-duration: 8s;
  -webkit-animation-name: backgroundchangeFadeInOut;
  -webkit-animation-timing-function: ease-in-out;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-duration: 8s;
}

Example 4

Fullscreen Background Image Slideshow with CSS3

Last updated