Skip to content

Instantly share code, notes, and snippets.

@Yelakelly
Last active March 22, 2017 12:17
Show Gist options
  • Save Yelakelly/026f5eee5aa6af2c56ca9e3a73580318 to your computer and use it in GitHub Desktop.
Save Yelakelly/026f5eee5aa6af2c56ca9e3a73580318 to your computer and use it in GitHub Desktop.
Magnific popup - Gallery
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
</head>
<body>
<div class="images">
<a href="http://lorempixel.com/600/600" class="image-popup"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
<a href="http://lorempixel.com/600/600" class="image-popup"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
<a href="http://lorempixel.com/600/600" class="image-popup"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
<a href="http://lorempixel.com/600/600" class="image-popup"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
<a href="http://lorempixel.com/600/600" class="image-popup"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
</div>
<div class="zoom-gallery">
<a href="http://lorempixel.com/600/600"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
<a href="http://lorempixel.com/600/600"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
<a href="http://lorempixel.com/600/600"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
<a href="http://lorempixel.com/600/600"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
<a href="http://lorempixel.com/600/600"><img class="images__item" src="http://lorempixel.com/200/200"/></a>
</div>
</body>
</html>
.mfp-no-margins img.mfp-img {
padding: 0;
}
/* position of shadow behind the image */
.mfp-no-margins .mfp-figure:after {
top: 0;
bottom: 0;
}
/* padding for main container */
.mfp-no-margins .mfp-container {
padding: 0;
}
/*
for zoom animation
uncomment this part if you haven't added this code anywhere else
*/
/*
.mfp-with-zoom .mfp-container,
.mfp-with-zoom.mfp-bg {
opacity: 0;
-webkit-backface-visibility: hidden;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.mfp-with-zoom.mfp-ready .mfp-container {
opacity: 1;
}
.mfp-with-zoom.mfp-ready.mfp-bg {
opacity: 0.8;
}
.mfp-with-zoom.mfp-removing .mfp-container,
.mfp-with-zoom.mfp-removing.mfp-bg {
opacity: 0;
}
*/
$(document).ready(function(){
$('.image-popup').magnificPopup({
type: 'image',
closeOnContentClick: true,
closeBtnInside: false,
fixedContentPos: true,
mainClass: 'mfp-no-margins mfp-with-zoom', // class to remove default margin from left and right side
image: {
verticalFit: true
},
zoom: {
enabled: true,
duration: 300 // don't foget to change the duration also in CSS
}
});
$('.zoom-gallery').magnificPopup({
delegate: 'a',
type: 'image',
closeOnContentClick: false,
closeBtnInside: false,
mainClass: 'mfp-with-zoom mfp-img-mobile',
image: {
verticalFit: true,
titleSrc: function(item) {
return item.el.attr('title') + ' &middot; <a class="image-source-link" href="'+item.el.attr('data-source')+'" target="_blank">image source</a>';
}
},
gallery: {
enabled: true
},
zoom: {
enabled: true,
duration: 300, // don't foget to change the duration also in CSS
opener: function(element) {
return element.find('img');
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment