Image appearing with Fad-in effect after loading page

Asked

Viewed 2,124 times

0

I need to make four images appear, one at a time, on my page, after her upload.

EFFECT ON THE IMAGE: It would be the fade-in effect, if I’m not mistaken that’s the name. That effect is the one that the image is emerging from the center of it.

LOADING OF EACH IMAGE Each image should appear after loading the page, one at a time, that is, if the first opens in 1 second the second would open in 3, being a difference of 2 seconds for each image.

  • 2

    If you want help, tips or guidelines, instead of something like "do my job for me," then you might have better luck. Post your code, even if it is incomplete (preferably compilable, if possible) or even if it has bugs and errors and ask for help. If you tried to do and made a mistake you don’t know what the solution is, this is the right place to ask for help. The only thing you can’t expect is someone to do everything.

3 answers

0


Treat animation with Javascript if the number of images is dynamic. If you have a fixed number of images, you can create your animation fade-in with @keyframes and make use of the property animation.

Delay between images can be done with the property animation-delay.

Each image can have its rule individually defined by the pseudo class :ntd-child(n).

Having everything set, you will need to use Javascript only to change the animation-play-state when the document is loaded (in that question there is more information on how to do this cross-browser) of paused for running. In the snippet below, I will apply a class to body to make this control.

document.addEventListener('DOMContentLoaded', function(){
  document.querySelector('body')
          .classList
          .add('loaded');
});
@keyframes fade-in {
  from { opacity: 0 }
  to   { opacity: 1 }
}

img {
  opacity: 0;
  animation: fade-in 2s normal forwards ease-in-out;
  animation-play-state: paused
}

body.loaded img {
  animation-play-state: running
}

body.loaded img:nth-child(2){ animation-delay: 1s }
body.loaded img:nth-child(3){ animation-delay: 2s }
body.loaded img:nth-child(4){ animation-delay: 3s }
<img src='http://lorempixel.com/100/100/abstract/'>
<img src='http://lorempixel.com/100/100/abstract/'>
<img src='http://lorempixel.com/100/100/abstract/'>
<img src='http://lorempixel.com/100/100/abstract/'>

0

    
$(document).ready( function(){
      
    $('.fade').each( function(i){

    //DELAY TEMPO PARA EXECUTAR DEPOIS QUE A PAGINA CARREGA
    //ANIMATE TEMPO DE ANIMAÇÃO
    $(this).delay(2000).animate({'opacity':'1'},1500);

    }); 
      
});
#objeto{
background-color: #ddd;
width:50%;
margin:auto;
}

.style{
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="style">
        <div class="fade">
          <h1 class="">TESTE FADEIN</h1>
          <p class="lead">TESTE FADEIN QUANDO CARREGA A PÁGINA.</p>
        </div>
    </div>

0

> $(document).ready(function(){
> 
>    setTimeout(function(){
>         $('#elementoImg1').fadeIn(1000);
>         $('#elementoImg2').fadeIn(3000);
>          $('#elementoImg3').fadeIn(5000);
>          $('#elementoImg4').fadeIn(7000);
>    }, 1000);
> 
> });
  • You can also use a . delay() between the Fades, so everyone has the same animation speed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.