Jquery延迟5秒

问题描述 投票:-2回答:4

我有jquery我想延迟5秒的功能

$(target).slideDown("slow","linear", function(){ 
                    $(target).addClass('section-active');
                    $('html, body').animate({
                        scrollTop: $(target).offset().top
                    }, 1000, 'easeInOutExpo', function() {
                        isScrolling = false;
                        startNano.go();
                    });
                });

我怎样才能实现

jquery
4个回答
1
投票

内置javascript setTimeout。你也可以使用.delay方法来实现jquery 1.4.0+。 check it out here

setTimeout方法看起来像这样:

    $(target).slideDown("slow","linear", function(){ 
      setTimeout(function(){
      $(target).addClass('section-active');
      $('html, body').animate({
         scrollTop: $(target).offset().top
      }, 1000, 'easeInOutExpo', function() {
         isScrolling = false;
         startNano.go();
    });
  }, 5000); //5000 = 5 seconds
});

.delay方法如下:

$(target).slideDown("slow","linear", function(){ 
          $(target).addClass('section-active');
          $('html, body').delay(5000).animate({
             scrollTop: $(target).offset().top
          }, 1000, 'easeInOutExpo', function() {
             isScrolling = false;
             startNano.go();
        });

0
投票

使用setTimeout()。它在指定的毫秒数后调用函数或计算表达式

$(target).slideDown("slow","linear", function(){ 
  setTimeout(function(){
    $(target).addClass('section-active');
    $('html, body').animate({
        scrollTop: $(target).offset().top
    }, 1000, 'easeInOutExpo', function() {
        isScrolling = false;
        startNano.go();
    });
  }, 5000); //5 seconds
});

0
投票

使用setTimeout()功能

    setTimeout(function(){
       $(target).slideDown("slow","linear", function(){ 
       $(target).addClass('section-active');
       $('html, body').animate({
          scrollTop: $(target).offset().top
         }, 1000, 'easeInOutExpo', function() {
          isScrolling = false;
          startNano.go();
        });
      });
     },5000);

0
投票

您可以使用.delay(5000)这是一个jQuery函数来链接动画或回调事件之间的延迟。

然而,正如(如果我已经正确理解)你希望它在它做任何事情之前等待,我们可以通过在我们要求它延迟然后链接结束之前设置一个stop()来解决这个问题。

$('html, body').stop(true, true).delay(5000).animate(...)
© www.soinside.com 2019 - 2024. All rights reserved.