JQuery fade with loop and delay

前端 未结 7 863
谎友^
谎友^ 2020-12-10 20:37

I have 2 Divs stacked on top of each other.

I need a really simple function that will:

a) Wait for 3 seconds and then b) FadeOut the top Div to reveal the se

7条回答
  •  余生分开走
    2020-12-10 20:59

    I know this is old, but I thought I would share what I did to accomplish this

    $(document).ready(function() {
        var delay = 500;
        $("#mydiv").bind('fadein', function()
        {
            $(this).fadeOut(1000, function()
            {
                $(this).delay(delay).trigger('fadeout');
            });
        });
    
        $("#mydiv").bind('fadeout', function()
        {
            $(this).fadeIn(1000, function()
            {
                $(this).delay(delay).trigger('fadein');
            });
        });
    
        $("#mydiv").fadeIn(1000, function()
        {
            $(this).trigger("fadein");
        });
    });
    

    then call this when you want it to stop

    $("#mydiv").stop().hide();
    

提交回复
热议问题