Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This can be achieved by modifying the CSS of the loader element using JavaScript or jQuery. The following steps can be followed:

  1. Create a loader element in HTML with its own CSS styles.

  2. Add a CSS class to the loader element that sets it to display: none.

  3. When the form is submitted, use JavaScript to remove the display: none class from the loader element so that it becomes visible.

  4. Modify the CSS styles of the loader element using JavaScript or jQuery to change its appearance, such as the color or size.

  5. Once the form submission is complete, use JavaScript to add back the display: none class to the loader element to hide it again.

Example code:

HTML:

<div id="loader" class="hidden">
  <i class="fa fa-spinner fa-spin"></i>
</div>

CSS:

.hidden {
  display: none;
}

#loader {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  color: #fff;
  font-size: 3rem;
}

JavaScript:

const form = document.querySelector('#my-form');
const loader = document.querySelector('#loader');

form.addEventListener('submit', function() {
  loader.classList.remove('hidden');
  loader.style.color = '#f00';
});

// after form submission is complete:
loader.classList.add('hidden');