I am really new to jQuery but am familiar with some other languages. I recently bought a quiz type script and I am trying to add a simple 15 second timer to each question. This is just a fun poll, so no need to worry about users playing with javascript to increase time, etc.
In principle, if the user does not ask a question within 15 seconds, he will automatically proceed to the next question and the timer will start again.
The answers have a .next tag, and when it is selected, it moves on to the next question, as the code below is (hopefully).
superContainer.find('.next').click(function () { $(this).parents('.slide-container').fadeOut(500, function () { $(this).next().fadeIn(500) }); return false });
The problem I have is if I use setInterval , I do not know how I can select the appropriate div again to fade it out and disappear in the next one. I tried the code below and some similar patchwork ideas, but it doesnβt work, but maybe this will give a better idea of ββwhat I need.
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 });
I used jQuery only a day or two to justify any obvious errors and bad code! Let me know if you need any other code or information.
john
source share