HLJ 发布于
2018-08-09 17:25:41

点击图片放大预览photoswipe插件

        知道开发和产品及设计势不两立的局面吗?今天又深感同受了!本来呢设计稿上就没有说明图片放大功能这个需求的。项目到了尾声了。测试说:这里的图片需要点击放大并可以左右循环滑动切换。设计说:是有这样的功能!组长说:什么时候能开发完成!完成?想的到是挺美的!工作排的满满的怎么也得有个先来后到吧!这个一个个的都像是催命符。好吧!我妥协了,这就用photoswipe插件给你们弄个图片放大功能,堵上你们的嘴!看你们还说

引用文件:
photoswipe/4.1.0/photoswipe.css
photoswipe/4.1.0/default-skin/default-skin.css
photoswipe/4.1.0/photoswipe.min.js
photoswipe/4.1.0/photoswipe-ui-default.min.js

1、html代码:
<div id="gallery">
  <figure class="photo" role="img">
    <a href="https://photo.page">
      <img src="https://unsplash.it/1200/900/?image=702"
       data-caption="Sea side, south shore<br><em class='text-muted'>© Dominik Schr?der</em>" 
       data-width="1200" data-height="900" itemprop="thumbnail" alt="Image description">
    </a>
  </figure>
</div>

<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 class="pswp__preloader__icn">
            <div class="pswp__preloader__cut">
              <div class="pswp__preloader__donut"></div>
            </div>
          </div>
        </div>
      </div>
      <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
        <div class="pswp__share-tooltip"></div>
      </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>
2、JavaScript代码:
(function($) {
  var container = [];
  
  $('#gallery').find('figure').each(function() {
    var $link = $(this).find('img'),
      item = {
        src: $link.attr('src'),
        w: $link.data('width'),
        h: $link.data('height'),
        title: $link.data('caption')
      };
    container.push(item);
  });

  $('img').click(function(event) {
    event.preventDefault();
    var $pswp = $('.pswp')[0],
      options = {
        index: $(this).closest('figure').index(),
        bgOpacity: 0.9,
        showHideOpacity: true
      };
    var gallery = new PhotoSwipe($pswp, PhotoSwipeUI_Default, container, options);
    gallery.init();
  });

}(jQuery));
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-08-09/53.html
最后生成于 2024-05-27 22:52:35
此内容有帮助 ?
0