Good morning!
I am using the great SimpleModal plugin for jQuery from Eric Martin. Currently, I am loading a modal using an iframe to load my requested pages which works as expected. What I would like to implement is a Loading... spinner which displays while the content is loading.
I am loading my modal as follows:
jQuery(function ($) {
// Load dialog on click
$('.basic').click(function (e) {
var src = "http://localhost" + $(this).attr("href");
$.modal('<iframe id="details" class="so" src="' + src + '" height="500" width="500" style="border:0">', {
closeHTML: "<a title='Close' class='modalCloseImg simplemodal-close'></a>",
containerId: "simplemodal-container",
overlayId: "simplemodal-overlay",
overlayClose: true
});
return false;
});
});
I have a background image set for my modal-container, which displays right away. I would definitely prefer to show a loading spinner here as well.
I was able to solve this by inserting a loading div inside of the simplemodal source and then calling show/hide as needed from my code.
I am using a slightly extended version of spin.js for beautiful spinners and modal spinner overlays. It can be used on any element by simply:
or for modal spinners:
call spin again to turn off and remove the spinner again. This is how it looks like:
This is the spin.min.js including a jQuery extension and some default opts for modal spinners:
The simple answer for this is to use a load() and then place the code for the modal in load's callback. Here is an example, pseudo-code -
That way the iFrame loads the page containing the image immediately and then the modal.