Search code examples
jquerysequencefade

sequential letter fading not working in sequence, all fade in at same time jQuery


I'm trying to fade in a string of letters, I'm not sure why they aren't fading in at different times.

<script>
window.onload = function() {
$( "#A" ).fadeIn( "500" );
$( "#B" ).fadeIn( "600" );
$( "#C" ).fadeIn( "700" );
$( "#D" ).fadeIn( "800" );
$( "#E" ).fadeIn( "900" );
$( "#F" ).fadeIn( "1000" );
$( "#G" ).fadeIn( "1100" );
$( "#H" ).fadeIn( "1200" );
$( "#I" ).fadeIn( "1300" );
$( "#J" ).fadeIn( "1400" );
$( "#K" ).fadeIn( "1500" );
$( "#L" ).fadeIn( "3600" );
}
</script>

Solution

  • When you add time as 500, 600, the speed of fading will change but it will start fading at same time. Your code should be

    $(document).ready(function ()
    {
    
         $("#A").fadeIn( 500,function ()
         {
            $("#B").fadeIn( 500,function ()
             {
                    $("#C").fadeIn(500,function ()
                     {
    
                     });
             });
         });
    });
    

    added callback function which will fade one after the other