JQuery delay before fadeOut

前端 未结 3 895
小鲜肉
小鲜肉 2021-02-12 09:21

I have written a jquery script that allows me to fade divs in and out, then repeat. The code works fine. However, when I try to add a delay (I want the div to stay up a few seco

3条回答
  •  醉话见心
    2021-02-12 10:02

    try this

    $(document).ready(function(){
       ShowPostDiv(0);
    });
    
    function ShowPostDiv(divIndex)
    {
        $(".home_entry_txt").hide();
    
        if(divIndex >= $(".rotate_hide").length)
        {
            divIndex = 0;
        }
        var divPostHtml = $(".rotate_hide:eq("+divIndex+")").html();
        $(".home_entry_txt").html(divPostHtml); 
        $(".home_entry_txt").fadeIn(3000, function(){
            setTimeout(function(){
                $(".home_entry_txt").fadeOut("slow");
            },4000);
        });
        divIndex++;
    }
    

提交回复
热议问题