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
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.
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.
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").
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.
Try using Ladda.stopAll(); See here: https://github.com/hakimel/Ladda
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With