【问题标题】:Run jquery events simultaneously同时运行 jquery 事件
【发布时间】:2016-08-10 01:05:25
【问题描述】:

我有一个 jQuery 测验,要开始测验,您必须单击“开始”按钮。 Onclick,标题文本被删除,测验垂直居中(所有这些都应该同时发生)。但是,由于我的代码,标题文本被删除然后测验居中。如何让它们同时运行?

这是我的错误代码:

  $('#get-started').click(function(){
    $('#index-banner').fadeOut(200, "swing"); 
    $('#begin-exam').delay(210).fadeOut(180, "swing");

    setTimeout(function(){
        $('#content').animate({top:'25%'},700).addClass('center-exam');
  }, 209);
   
  });

'center-exam' 类只是在测验中添加一个'absolute'的位置,以便它可以垂直居中

【问题讨论】:

    标签: javascript jquery jquery-events fadeout simultaneous


    【解决方案1】:

    当您将 .animate 和 .addClass 与“.”连接在一起时一个运行并完成,然后另一个运行。通过将它们放在单独的语句中,它们可以并且将会尽可能地同时运行。

    $('#get-started').click(function(){
    $('#index-banner').fadeOut(200, "swing"); 
    $('#begin-exam').delay(210).fadeOut(180, "swing");
    
    setTimeout(function(){
        $('#content').animate({top:'25%'},700);
        $('#content').addClass('center-exam');
     }, 209);
    });
    

    【讨论】:

    • 是否需要任何其他解释来改进您的答案?
    猜你喜欢
    • 2013-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    相关资源
    最近更新 更多