JQuery - display delayed responses
I have set up some interactive labs for the course I am teaching, such as questions / answers. The student sees a "question" such as "Use cp command to copy file1 to file2". When they click on it, the answer is displayed below:cp file1 file2
But the students are lazy, they just go through and click on the answers, type commands verbatim and don't learn. I changed the code so that every click hides all other responses and adds a delay of 10 seconds before displaying. But the problem is that there are very few reviews per click. I would like to maybe display the next element, but without its content, or maybe loading a gif?
Here is my actual code:
.answer {
display: inline-block;
background: #333;
color: #999;
font-family: monospace;
}
$(document).ready(function(){
$(".step").next().hide();
$("li").click(function(){
$(".answer").hide();
$(this).next().delay(10000).show(0);
$("li").show();
});
});
<li class="step">Use the <code>cp</code> command to copy file1 to file2.</li>
<div class="answer">
$ <span class="cmd">cp file1 file2</span>
</div>
What's the best way to get the div to display, but put a delay (or gif loading) on ββthe content?
(Also, I am a complete jQuery noob, so if I did anything ridiculous please point it out.)
Thank!
source to share
Perhaps you can animate the visibility css property of the response container.
See jQuery.animate () documentation . This allows you to play not only with the duration of the animation, but also with the easing function to be used.
That is, a function that determines the change in the speed of an animation over its duration.
jQuery only does two relaxation functions by default, but there is more on jQuery-UI , and if I'm not mistaken, you can implement your own (I never did).
Thus, you can start with little visibility and low or no increments over the time, and end rendering only in the last seconds of the entire delay.
source to share