Remove animation timing function flicker

1

I had a doubt. I wanted to get the background of my web to change using keyframes. That's why I used animation-timing-function: step-start; . The problem is that it does change, but in each change there is a horrible white flicker, as if the image were removed and the background was seen. I wish there was not that flicker. This is my CSS code:

body{
    margin: 0;
}

#container{
   position: absolute;
   width: 100%;
   min-height: 100%;
   margin: 0 auto;
   background-image: url("../IMAGES/cancha.png");
   background-size: cover;
   background-repeat: no-repeat;
   animation-timing-function: step-start;
   animation-name: animacion;
   animation-fill-mode: forwards;
   animation-duration: 10s;
}

@keyframes animacion {
  0% {
    background-image: url("../IMAGES/cancha1.png");
    animation-timing-function: steps(1, start);  
  }

  7% {
    background-image: url("../IMAGES/cancha2.png");
    animation-timing-function: steps(1, start);  
  }

  15% {
    background-image: url("../IMAGES/cancha3.png");
    animation-timing-function: steps(1, start);  
  }

  22% {
    background-image: url("../IMAGES/cancha4.png");
    animation-timing-function: steps(1, start);  
  }

  29% {
    background-image: url("../IMAGES/cancha5.png");
    animation-timing-function: steps(1, start);  
  }

  36% {
    background-image: url("../IMAGES/cancha6.png");
    animation-timing-function: steps(1, start);  
  }

  43% {
    background-image: url("../IMAGES/cancha7.png");
    animation-timing-function: steps(1, start);  
  }

  50% {
    background-image: url("../IMAGES/cancha8.png");
    animation-timing-function: steps(1, start);  
  }

  57% {
    background-image: url("../IMAGES/cancha9.png");
    animation-timing-function: steps(1, start);  
  }

  63% {
    background-image: url("../IMAGES/cancha10.png");
    animation-timing-function: steps(1, start);  
  }

  70% {
    background-image: url("../IMAGES/cancha11.png");
    animation-timing-function: steps(1, start);  
  }

  77% {
    background-image: url("../IMAGES/cancha12.png");
    animation-timing-function: steps(1, start);  
  }

  84% {
    background-image: url("../IMAGES/cancha13.png");
    animation-timing-function: steps(1, start);  
  }

  91% {
    background-image: url("../IMAGES/cancha14.png");
    animation-timing-function: steps(1, start);  
  }

  100% {
    background-image: url("../IMAGES/cancha.png");
    animation-timing-function: steps(1, start);  
     }
  }
}

And this is my HTML and JavaScript code (I know that the javascript code is only messages per console, so I doubt it's the problem, but I put it just in case). I guess the error will be in animation-timing-function: step-start; but I do not know how to fix it:

<!DOCTYPE html>
<html>
<head>
    <title>BASKETBALL</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../CSS/principal.css">
</head>
<script type="text/javascript">
$(document).ready(function(){
    var container = document.getElementById('container');

    container.addEventListener("animationstart", listener, false);
    container.addEventListener("animationend", listener);
    container.addEventListener("animationiteration", listener, false);


    function listener(container){
        switch(container.type) {
            case "animationstart":
                console.log("Started: elapsed time is ");
                break;
            case "animationend":
                console.log("Ended: elapsed time is ");
                break;
            case "animationiteration":
                console.log("New loop started at time ");
                break;
        }
    }

});
</script>
<body>
    <div id="container"></div>
</body>
</html>

In case you have any questions about the code do not hesitate to ask me. Thanks

  

Hello, what browser are you using? Could you see if a different browser has the same flaw please? - Genarito

I'm using Chromium and in Chrome the same thing happens to me. In firefox I have not tried it because I do not know what things I have to modify to make it work.

The images are all 1000x544 and all weigh almost the same, between 580KB and almost 600KB. I have an MSI with an Intel i-7 processor, so I guess it has enough power to load the images.

    
asked by Adrian Rodriguez 05.01.2017 в 18:47
source

1 answer

3

Instead of making an animation by modifying the background, you could make an animation by modifying images inside the container.

Example:

@keyframes fadeInOut {
  0% {
    opacity:1;
  }
  17.5% {
    opacity:1;
  }
  25% {
    opacity:0;
  }
  92.5% {
    opacity:0;
  }
  100% {
    opacity:1;
  }
}
#container {
  position:relative;
  height:281px;
  width:450px;
  margin:0 auto;
  overflow: hidden;
}
#container img {
  position:absolute;
  left:0;
  width: 100%;
}

#container img {
  animation-name: fadeInOut;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-duration: 8s;
}
#container img:nth-of-type(1) {
  animation-delay: 6s;
}
#container img:nth-of-type(2) {
  animation-delay: 4s;
}
#container img:nth-of-type(3) {
  animation-delay: 2s;
}
#container img:nth-of-type(4) {
  animation-delay: 0;
}
<div id="container">
  <img src="https://kbdevstorage1.blob.core.windows.net/asset-blobs/19201_en_1"/>
  <img src="https://kbdevstorage1.blob.core.windows.net/asset-blobs/19889_en_1"/>
  <img src="https://ioyby2hf25e3sg55t3muegr1-wpengine.netdna-ssl.com/wp-content/uploads/2015/10/calm-boat-wallpaper.jpg"/>
  <img src="http://www.highreshdwallpapers.com/wp-content/uploads/2012/02/Windows-Vista-Beach-Wallpaper-1024x768.jpg"/>
</div>

To use "n" images you should do the following calculations:

n = 4 // Total imagenes
a = 1.4s // Tiempo que se vera una imagen
b = .6s // Tiempo desvanecimiento entre imágenes

t = (a+b)*n => 8s // Tiempo total de la animación (eg: animation-duration)
d = (a+b) => 2s // Tiempo de retardo de la animación (eg: animation-delay)

Percentages of the Keyframes:

0%
a/t*100% => 17.5%
(a+b)/t*100% => 25%
100%-(b/t*100%) => 92.5%
100%

Source: Cross fading images

    
answered by 05.01.2017 / 20:30
source