Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Stopping ladda animation spinning wheel of death

I have a terms & condition checkbox. If it's checked, it submits the form otherwise it throws up an alert. When the alert dialogue box is thrown, the spinning wheel spins for eternity.

I am using the ladda zoom-in gif as listed here: http://lab.hakim.se/ladda/

Before clicking on the button, here's the generated html code:

<button type="submit" id="ladda-purple-step4" class="ladda-button ladda captilize step-4-btn" data-color="purple" data-style="zoom-in">Book appointment now</button>

When spinning begins:

<button type="submit" id="ladda-purple-step4" class="ladda-button ladda captilize step-4-btn" data-color="purple" data-style="zoom-in" disabled data-loading>Book appointment now</button>

For the alert I have:

$('#ladda-purple-step4').unbind('click').click(function (e) {
    if (!document.getElementById('termsagree').checked) {
        e.preventDefault();
        alert("You must accept the Terms & Conditions.");
    }
});

I have managed to stop this on parts of the website using this code:

$('#ladda-purple-step4').on('click', function (e) {
    $('#ladda-purple-step4').attr("disabled", false);
    $('#ladda-purple-step4').removeAttr("data-loading");
});

But it's not working here as this initiates before the spinning begins. My question is, I'm looking for a way to stop the spinning. I was thinking if I can find the attribute data-loading, then fire off my code? What do you recommend? How would I do that?

Thanks

like image 307
DarkShadowAY Avatar asked Jul 07 '14 08:07

DarkShadowAY


People also ask

How to stop an animation before it is finished using jQuery?

The jQuery stop () method is used to stop an animation or effect before it is finished. The stop () method works for all jQuery effect functions, including sliding, fading and custom animations. The optional stopAll parameter specifies whether also the animation queue should be cleared or not.

How do you animate in jQuery?

jQuery Animations - The animate() Method. The jQuery animate() method is used to create custom animations. Syntax: $(selector).animate({params},speed,callback); The required params parameter defines the CSS properties to be animated. The optional speed parameter specifies the duration of the effect.

How to stop the animation effect of a <div> element?

Default is false. So, by default, the stop () method kills the current animation being performed on the selected element. The following example demonstrates the stop () method, with no parameters: Use a jQuery method to stop the animation effect of a <div> element. $ ("div").

Do I have to hide the spinner when loading an animation?

You do not have to hide the spinner, because when the request completes, a new page is rendered where the spinner is not visible. This entry was posted in Java Web Frameworks and tagged jquery, loading animation, spinner.


1 Answers

Try using Ladda.stopAll(); See here: https://github.com/hakimel/Ladda

like image 76
Bryan Avatar answered Oct 19 '22 19:10

Bryan