Or Weinberger
Or Weinberger

Reputation: 7482

Load images in jQuery modal only on modal open

I have a modal div which is hidden by default.

The div contains a few images and I want to load the page as quickly as possible.

Is it possible to actually load the images only when the modal is opened and not before?

Upvotes: 0

Views: 945

Answers (2)

Srihari Goud
Srihari Goud

Reputation: 852

Yes it is possible, you have to load the images into the divider when the user clicks a link model ,

For this you need to write an ajax call to load the images after clicking the link

Upvotes: 0

Constantinius
Constantinius

Reputation: 35069

If you are using a model Dialog this is easy if you append the img element when the dialog is shown for the first time. You can do this via the open event of the Dialog:

var hasOpened = false;

$( "#dialog" ).dialog({
   autoOpen: false,
   open: function(event, ui) { 
      if (!hasOpened) {
         $('#dialog').append($('<img src="someurl"></img>'));
      }
   }
});

Upvotes: 1

Related Questions