我对 jQuery 很陌生,但熟悉其他一些语言。我最近买了一个测验类型的脚本,我试图为每个问题添加一个简单的 15 秒计时器。这只是一个有趣的测验,因此无需担心用户使用 javascript 来增加时间等。
基本上,如果用户在 15 秒内没有选择一个问题,它将自动进入下一个问题,并且计时器重新开始。
Answers have the .nexttag, and when chosen it moves onto the next question as the code below shows (hopefully).
superContainer.find('.next').click(function () {
$(this).parents('.slide-container').fadeOut(500, function () {
$(this).next().fadeIn(500)
});
return false
});
我遇到的问题是,如果我使用setInterval,我不知道如何再次选择适当的 div 来淡化它并淡入下一个。我已经尝试了下面的代码和一些类似的好斗的想法,但它不起作用,但也许它会让我更好地了解我所追求的。
superContainer.find('.next').click(function () {
$active_count = $count;
countInterval = setInterval(function() {
$active_count--;
if($active_count <= 0){
clearInterval(countInterval);
$active_count = $count;
$(this).parents('.slide-container').fadeOut(500, function () {
$(this).next().fadeIn(500)
});
}
$('.question-timer').html($active_count);
}, 1000);
$(this).parents('.slide-container').fadeOut(500, function () {
$(this).next().fadeIn(500)
});
return false
});
我只使用 JQuery 一两天,所以请原谅任何明显的错误和糟糕的代码!如果您需要任何其他代码或信息,请告诉我