I'm trying to determine how to stop a recursive function call that came from a click to 'start_button' by calling a different function when 'stop_button' is clicked.
- User clicks 'start_button' and the slide down/up animation continues to loop "infinitely" until...
- User clicks 'stop_button' and the looped animations will stop.
I'd like to keep two different buttons instead of having one dual-purpose start/stop button. With my code below, the animation starts and loops, but does not stop when clicking the stop button. I'd like for the stop button to stop the animation when clicked.
var stopSliding = false;
$('#stop_button').click(function(){
stopSliding = true;
});
$('#start_button').click(function infiniteLoop(){
if (stopSliding == true)
{
$('#top_message').stop();
return;
}
else
{
$('#top_message').hide().slideDown(2000);
$('#top_message').slideUp(2000);
infiniteLoop();
return;
}
});