Advertisement
Guest User

Retina for magnificPopup lightbox gallery (Crafto HTML Template)

a guest
May 24th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     if (typeof $.fn.magnificPopup === 'function') {
  2.         var lightboxgallerygroups = {};
  3.         $('.portfolio-box [data-group], .gallery-box [data-group]').each(function () {
  4.             var id = $(this).attr('data-group');
  5.             if (!lightboxgallerygroups[id]) {
  6.                 lightboxgallerygroups[id] = [];
  7.             }
  8.             lightboxgallerygroups[id].push(this);
  9.         });
  10.  
  11.         $.each(lightboxgallerygroups, function () {
  12.             $(this).magnificPopup({
  13.                 type: 'image',
  14.                 closeOnContentClick: true,
  15.                 closeBtnInside: false,
  16.                 gallery: { enabled: true },
  17.                 retina: {
  18.                     ratio: 2,
  19.                     replaceSrc: function(item, src) {
  20.                         var srcset = $(item.el).attr('data-srcset');
  21.                         return srcset && window.devicePixelRatio >= 2 ? srcset.split(' ')[0] : item.src;
  22.                     }
  23.                 }
  24.             });
  25.         });
  26.     }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement