简体   繁体   English

添加setTimeout后,为什么jQuery函数在“ else if”处停止运行?

[英]why does my jQuery function stop running at “else if” after I add a setTimeout?

I'm trying to build a sort of copy of the fullPage.js plugin effect, except what mine does is play with the height of each of my "slides" instead of their positioning. 我正在尝试构建fullPage.js插件效果的一种副本,除了我所做的是发挥每个“幻灯片”的高度而不是它们的位置。 My function runs alright the first time around at "if", but once it gets to the "else if" it stops running. 我的函数在“ if”处第一次正常运行,但是一旦到达“ else if”,它就会停止运行。 Can anyone shed some light on why this is doing that? 谁能阐明为什么这样做吗?

if (currentSlide == 1) {

$("#slide-1").addClass("next-slide");
isAnimating = true;

setTimeout(function(){
  isAnimating = false;
  currentSlide++;
  console.log(currentSlide);
  console.log(isAnimating);
}, 900)

} else if ((currentSlide == 2) && (isAnimating)) {

alert();
$("#slide-2").addClass("next-slide");
currentSlide++;
console.log('Current slide is: ' + currentSlide);

}

根据示例中的代码,看起来在回调函数执行之后currentSlide == 2 && isAnimating永远不会为真,因此,如果在执行此逻辑块所在的函数之前执行回调函数,则else if内的代码else if不执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 setInterval function 无法阻止 setTimeOut 运行? - Why setInterval function cannot stop setTimeOut from running? 无法停止在setTimeout上运行的功能 - Can not stop the function running on setTimeout 将不相关的div添加到DOM后,为什么JQuery UI Datepicker停止工作? - Why does JQuery UI Datepicker stop working after I add an unrelated div to the DOM? 如果我添加 if 语句,为什么我的 jQuery 自动刷新停止工作? - why does my jQuery auto-refresh stop working if I add in a if statement? 如何停止运行此setTimeout函数? - How can I stop this setTimeout function from running? 将jquery插件放入div容器后,为什么我的jquery插件停止工作? - Why does my jquery plugin stop working after I put it in a div container? 为什么我的jQuery队列执行一次后就停止工作? - Why does my jQuery queue stop working after executing once? 为什么递归/嵌套的`setTimeout`在没有`else`语句的情况下不会停止执行? - Why does recursive/nested `setTimeout` does not stop execution without an `else` statement? 为什么 jQuery 插件会阻止我的自定义 function 工作? - Why does a jQuery plugin stop my custom function from working? 为什么setTimeout(myFunction,0)有效,但运行函数本身不起作用? - Why does setTimeout(myFunction, 0) work, but running the function itself not work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM