How can I stop images from being loaded by below's jQuery each() function?
As soon as a modal window opens, I load images as follow:
HTML:
<img data-src='image1.jpg'/>
<img data-src='image2.jpg'/>
<img data-src='image3.jpg'/>
jQuery:
$('img[data-src]').each(function(){
var imgsrc = $(this).attr('data-src');
$(this).attr('src',imgsrc).on('load',function(){
$(this).removeAttr('data-src');
});
});
This works great, but I would like to abort this when the modal is closed. What's the best way of doing this?
The problem is that upon selecting an image in the modal, a larger size is being loaded. But that image doesn't appear until all the images in the modal finish loading.