Created
August 26, 2017 20:34
-
-
Save niamrox/bd76b39383139451340dcd7eeac6e3f3 to your computer and use it in GitHub Desktop.
Revisions
-
niamrox created this gist
Aug 26, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ initApplyImageLoad: function () { var $container = $('.site-content'); var $status = $('#status'); var $progress = $('progress'); var supportsProgress = $progress[0] && // IE does not support progress $progress[0].toString().indexOf('Unknown') === -1; var loadedImageCount, imageCount; $(window).load( function() { $('.site-content img').wrap("<div class='img-wrap is-loading'></div>"); // var $item = $('.site-content img').parent(); // $item.addClass('is-loading'); // use ImagesLoaded $container.imagesLoaded() .progress( onProgress ) .always( onAlways ); imageCount = $container.find('img').length; resetProgress(); updateProgress( 0 ); }); // return doc fragment with function getItems() { var items = ''; for ( var i = 0; i < 7; i++ ) { items += image.img.src; } return items; } function resetProgress() { $status.css({ opacity: 1 }); loadedImageCount = 0; if ( supportsProgress ) { $progress.attr( 'max', imageCount ); } } function updateProgress( value ) { if ( supportsProgress ) { $progress.attr( 'value', value ); } else { // if you don't support progress elem $status.text( value + ' / ' + imageCount ); } } // triggered after each item is loaded function onProgress( imgLoad, image ) { // change class if the image is loaded or broken var $item = $( image.img ).parent(); $item.removeClass('is-loading'); if ( !image.isLoaded ) { $item.addClass('is-broken'); } // update progress element loadedImageCount++; updateProgress( loadedImageCount ); } // hide status when done function onAlways() { $status.css({ opacity: 0 }); } },