How can I fade out a div using jQuery?

前端 未结 7 1972
孤街浪徒
孤街浪徒 2020-12-05 09:46

Is there any way to fadeout a div after 5 Seconds without using a setTimeOut function?

7条回答
  •  青春惊慌失措
    2020-12-05 10:12

    Case 1: if you want to start fadeOut after 5 seconds, use this:

    jQuery.fn.delay = function(time,func){
        return this.each(function(){
            setTimeout(func,time);
        });
    };
    

    Then, use it like this:

    $('#div').delay(5000, function(){$(#div').fadeOut()})
    

    You can't achieve this without using setTimeOut at all

    Case 2: if you want the duration of fadeOut to be 5 seconds, use this:

    $('#div').fadeOut(5000)
    

提交回复
热议问题