Advertisement
artemsemkin

Untitled

Oct 27th, 2022
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Grid = function ($target = $('.js-grid')) {
  2.   if (!$target.length) {
  3.     return;
  4.   }
  5.  
  6.   $target.each(function () {
  7.  
  8.     var
  9.       $current = $(this),
  10.       $currentLazyImages = $current.find('img[data-src]'),
  11.       currentInstance;
  12.  
  13.     currentInstance = $current.isotope({
  14.       itemSelector: '.js-grid__item',
  15.       columnWidth: '.js-grid__sizer',
  16.       percentPosition: true
  17.     });
  18.  
  19.     loadLazyImages($currentLazyImages, false, function () {
  20.       $current.imagesLoaded().always(function () {
  21.         currentInstance.isotope('layout');
  22.       });
  23.     });
  24.  
  25.     // update non-lazy images
  26.     $current.imagesLoaded().always(function () {
  27.       currentInstance.isotope('layout');
  28.     });
  29.  
  30.     // =============== Add this =============== //
  31.     currentInstance.on('arrangeComplete', function () {
  32.       loadLazyImages($currentLazyImages, false);
  33.     });
  34.  
  35.   });
  36.  
  37.   return $target;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement