Created
August 5, 2014 15:46
-
-
Save victorono/4cf37db127a4a38732fa to your computer and use it in GitHub Desktop.
Lazy load bootstrap carousel images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('div.modal').on('show.bs.modal', function(e){ | |
| var carousel = $(this).find('.carousel').hide(); | |
| var deferreds = []; | |
| var imgs = $('.carousel', this).find('img'); | |
| imgs.each(function(){ | |
| var self = $(this); | |
| var datasrc = self.attr('data-src'); | |
| if (datasrc) { | |
| var d = $.Deferred(); | |
| self.one('load', d.resolve) | |
| .attr("src", datasrc) | |
| .attr('data-src', ''); | |
| deferreds.push(d.promise()); | |
| } | |
| }); | |
| $.when.apply($, deferreds).done(function(){ | |
| carousel.fadeIn(1000); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment