JQuery fade with loop and delay

前端 未结 7 841
谎友^
谎友^ 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:48

    This attempt uses a small cookbook function wait from jquery.com.

    The function doFading assumes the id of the top div to be "a4".

    function doFading() {
          $("#a4").wait(3000)
          .fadeOut("slow")
          .wait(3000)
          .fadeIn("slow",doFading);
        }
    
    $.fn.wait = function(time, type) {
            time = time || 1000;
            type = type || "fx";
            return this.queue(type, function() {
                var self = this;
                setTimeout(function() {
                    $(self).dequeue();
                }, time);
            });
        };
    

提交回复
热议问题