【问题标题】:How to delay the jquery parts so they dont come on all at the same time?如何延迟 jquery 部分,使它们不会同时出现?
【发布时间】:2019-02-25 09:44:30
【问题描述】:

我希望 .title 出现,然后 .element 出现,然后是 .list。但是,我似乎无法弄清楚该怎么做。它们总是同时出现。

setTimeout(function() {
  $("#screen" + screenNum).show();
  $("#screen" + screenNum + " .title").each(function(index) {
    $(this).css("display", "block");
    TweenLite.from($(this), animationSpeed, {
      x: -1000,
      ease: Cubic.easeOut,
      delay: index * 0.1
    });
  });

  $("#screen" + screenNum + " .element").each(function(index) {
    $(this).css("display", "block");
    TweenLite.from($(this), animationSpeed, {
      y: 1080,
      ease: Cubic.easeOut,
      delay: index * 0.1
    });
  });

  $("#screen" + screenNum + " .list").each(function(index) {
    $(this).css("display", "block");
    TweenLite.from($(this), animationSpeed, {
      y: -500,
      ease: Cubic.easeOut,
      delay: index * 0.1
    });
  });
}, numEle * 100);

【问题讨论】:

  • 我认为这是因为您的超时包括所有内容。如果你分开做,它会起作用。或者你 tweek 延迟,因为我认为每个动作的延迟都是相等的

标签: javascript jquery function settimeout delay


【解决方案1】:

我可能会在jquery 中使用.load 函数,它的作用是第二个完成加载的内容将运行一个函数。您可以使用它来表示仅在文档加载时运行函数、在页面上的对象加载时运行它,甚至是另一个 javascript 函数。要使用它,只需使用

引用对象
$("object here").load(function); 

$("object").load(function(){

});

如果您想了解更多信息,请访问 w3schools 页面:https://www.w3schools.com/jquery/event_load.asp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多