【问题标题】:How do i delay this function [duplicate]我如何延迟此功能[重复]
【发布时间】:2015-04-22 17:28:53
【问题描述】:

我有这个代码:

$('a[href*=#]').click(function() {

  $('html, body').animate({
    scrollTop: $($.attr(this, 'href')).offset().top
  }, 500);

  return false;
});

但是点击链接后我需要 600ms 延迟,以便我的页面有机会执行我设置为 500ms 的其他操作,提前谢谢您

【问题讨论】:

    标签: javascript function href delay


    【解决方案1】:

    jQuery 有一个delay 方法

    $('a[href*=#]').click(function(){
        $('html, body').delay(600).animate({
            scrollTop: $( $(this).attr('href') ).offset().top
        }, 500);
    
        return false;
    });
    

    【讨论】:

    【解决方案2】:

    看看这个,

    $('a[href*=#]').click(function(){
    setTimeout(function()
    {
    
    // Things to do after 600ms
    
    },600);
    
    $('html, body').animate({
    scrollTop: $( $.attr(this, 'href') ).offset().top
    }, 500);
    return false;
    });
    

    【讨论】:

      猜你喜欢
      • 2013-05-28
      • 2017-07-18
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      相关资源
      最近更新 更多