Question :
I have a radio button that when clicked, performs a function that mounts a datepicker.
However, the mountDatepicker function only loads after a few seconds, after querying the three apis to mount the calendar.
So how do I load an image with a loader in place of the calendar while the function does not finish?
$("input[type='radio']").click(function(){
if ($("input[name='diasaluguel']:checked").length > 0 ) {
mountDatepicker();
}
});
Answer :
function addLoader(el) {
var gif = 'http://1.bp.blogspot.com/-Atj4ze_I-84/UeJk-CPeCsI/AAAAAAAAHno/UIbSZkTfWBA/s1600/loading.gif';
var img = document.createElement('img');
img.src = gif;
el.innerHTML = '';
el.appendChild(img);
}
Create a function to be run before mountDatepicker (); be called. You can do this in a different way: as I suggest, or already having a div that overlaps the HTML in the calendar.
As I did it adds a img
element to the calendar and then removes it.
Example: link