[英]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.