I have a bounce arrow on my website that I created using jquery and setInterval, for example:
bouncing = setInterval(function() { $("div").animate({ top:"30px" },100,"easeInCubic",function() { $("div").animate({ top:"0px" },100,"easeOutCubic"); }); console.log("bounced"); },200);
You can see it here in the encoder: http://codepen.io/mcheah/pen/wMmowr
I ran it faster than I needed because it is easier to see problems faster. My problem is that after you leave the interval for a few seconds, you will notice that instead of instantly bouncing back or down, the rebound element stops for half a second and then just holds there before starting again. If you leave it to work even longer (20 seconds) and then clear the interval, you will notice that it takes several seconds to stop the jump.
My questions are:
Why does a bounce sometimes fail?
Why does a clear interval take some time to clear if it repeats for a while?
Is there a better way to have a jumping arrow? Are CSS Transitions Improved?
Thank you for your help!
javascript jquery css
mcheah
source share