一、使用方法
<link rel="stylesheet" href="path/to/photoswipe.css">
<link rel="stylesheet" href="path/to/default-skin/default-skin.css">
<script src="path/to/photoswipe.min.js"></script>
<script src="path/to/photoswipe-ui-default.min.js"></script>
二、Html结构
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<div class="pswp__bg"></div>
<div class="pswp__scroll-wrap">
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<div class="pswp__preloader"></div>
<div class="pswp__preloader__icn"></div>
<div class="pswp__preloader__cut"></div>
<div class="pswp__preloader__donut"></div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap"></div>
<div class="pswp__share-tooltip"></div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
注意:代码中的pswp__bg、pswp__scroll-wrap、pswp__container和pswp__item的顺序不可以改变。
三、初始化插件
var pswpElement = document.querySelectorAll('.pswp')[0];
var items = [
{
src: 'https://placekitten.com/600/400',
width: 600,
height: 400
},
{
src: 'https://placekitten.com/1200/900',
width: 1200,
height: 900
}
];
var options = {
index: 0
};
var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();
KeyMob是最具价值的移动广告联盟;是国内最早专注于为移动应用APP开发者创造优质体验和手机广告收益最大化的平台。
<link rel="stylesheet" href="path/to/photoswipe.css">
<link rel="stylesheet" href="path/to/default-skin/default-skin.css">
<script src="path/to/photoswipe.min.js"></script>
<script src="path/to/photoswipe-ui-default.min.js"></script>
二、Html结构
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<div class="pswp__bg"></div>
<div class="pswp__scroll-wrap">
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<div class="pswp__preloader"></div>
<div class="pswp__preloader__icn"></div>
<div class="pswp__preloader__cut"></div>
<div class="pswp__preloader__donut"></div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap"></div>
<div class="pswp__share-tooltip"></div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
注意:代码中的pswp__bg、pswp__scroll-wrap、pswp__container和pswp__item的顺序不可以改变。
三、初始化插件
var pswpElement = document.querySelectorAll('.pswp')[0];
var items = [
{
src: 'https://placekitten.com/600/400',
width: 600,
height: 400
},
{
src: 'https://placekitten.com/1200/900',
width: 1200,
height: 900
}
];
var options = {
index: 0
};
var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();
KeyMob是最具价值的移动广告联盟;是国内最早专注于为移动应用APP开发者创造优质体验和手机广告收益最大化的平台。