This is a part of an JS-scanning function which runs about 3-5 times / sec.
Below is what I want to obtain .. but it (obviosly) does not work … because it keeps “resetting” the fadeIn function 3-5 times every second.
JavaScript
x
7
1
if (scanResult) {
2
dosomething();
3
} else {
4
// Show error message
5
$("#error").fadeIn().delay(3000).fadeOut();
6
}
7
I could call a seperate function and/or checks with timestamps when it last was called.
But … there must be a smarter jQuery-way?
Advertisement
Answer
Quick and dirty.
JavaScript
1
8
1
if (scanResult) {
2
dosomething();
3
} else {
4
// Show error message
5
if(!$("#error").hasClass("shown"))
6
$("#error").addClass("shown").fadeIn().delay(3000).fadeOut(() => {removeClass("shown");});
7
}
8