http://siwei.me/blog/posts/jquery-magnifit-popup
http://dimsemenov.com/plugins/magnific-popup/
使用步骤:
1. 添加 HTML:
<a class="image-popup-vertical-fit" href="http://big_image.jpg" title="Caption. Can be aligned to any side and contain any HTML."> <img src="http://small_image.jpg" width="75" height="75"> </a>
2. 添加 js:
// 图片点击后,全屏幕modal, 并显示大图 $('.image-popup-vertical-fit').magnificPopup({ type: 'image', closeOnContentClick: true, mainClass: 'mfp-no-margins mfp-with-zoom', image: { verticalFit: true }, // 这里是让图片的放大缩小有动画效果。 zoom: { enabled: true, duration: 300 // don't foget to change the duration also in CSS } });
3. 再添加 CSS, 要有外链,
https://raw.githubusercontent.com/dimsemenov/Magnific-Popup/master/dist/magnific-popup.css还要有下面这一段:
/* padding-bottom and top for image */ .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; } // 让黑色背景色有渐变效果 .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; }