灰儿 发表于 2017-12-16 04:17:03

PhotoSwipe用法

1、自动识别data-size问题,添加以下代码

gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
                  gallery.listen('imageLoadComplete',
                  function (index, item) {
                        var linkEl = item.el.children;

                        if (!linkEl.getAttribute('data-size') || linkEl.getAttribute('data-size') == 'auto') {
                            var img = new Image();
                            img.src = linkEl.getAttribute('href');

                            linkEl.setAttribute('data-size', img.naturalWidth + 'x' + img.naturalHeight);
                            item.w = img.naturalWidth;
                            item.h = img.naturalHeight;
                            gallery.invalidateCurrItems();
                            gallery.updateSize(true);
                        }
                  });
                  gallery.init();

页: [1]
查看完整版本: PhotoSwipe用法