0

Is there a way in JS/jQuery to "block" the loading of certain images in the DOM, up until a certain event occurs?

In my case, I have a page of products (WooCommerce Shop page) where clicking a product opens a modal window containing the image gallery of that particular product. But instead of loading galleries of all products on page load (too slow) I'd like to bind the loading of the image gallery to the opening of the modal window.

I'm guessing it's not really possible but perhaps there's some trick that comes close?

drake035
  • 3,955
  • 41
  • 119
  • 229

2 Answers2

1

You can add an img element in your modal window without any src attribute and update the src attribute based on the product selection.

Here's a Pen showcasing the idea :)

Arkantos
  • 6,530
  • 2
  • 16
  • 36
0

A satisfying way to achieve the same end result is to sabotage the src attribute of images, and then restore this attribute later on with JS.

Found at https://stackoverflow.com/a/5402812/871404 (thanks @arkantos too!)

Community
  • 1
  • 1
drake035
  • 3,955
  • 41
  • 119
  • 229
  • 1
    yea.. also, instead of `lsrc` you might want to do something like `data-src` or something. More meaningful as a HTML5 data attribute that nothing. – loxxy Jan 01 '16 at 12:56