0

图像是通过$.ajax

然后在内部创建 Photoswipe 实例$.ajax

当用户单击浏览器的后退按钮时尝试分离 Photoswipe 实例,但无法分离它。

有谁知道任何可能的解决方案来克服这个问题?

4

2 回答 2

0

终于找到了解决办法。请参考以下

$.ajax({
        网址:URL_TO_GET_JSON,
        成功:函数(json,状态){
            变种 p = [];
            $.each(json, 函数(a,b){
                //在这里画图。
            });
            $('.gallery').html(photo.join(''));


        // 在此处创建实例        
            var myPhotoSwipe = $(".gallery a").photoSwipe({
                启用鼠标轮:假,
            })

          /********** 此处未设置实例 *****************/

            $(document).bind('pagebeforechange', function(e) {
                if ($('.ps-carousel').length) {
                    $('body').removeClass('ps-active');
                    var photoSwipe = window.Code.PhotoSwipe;
                    var photoSwipeInstance = photoSwipe.getInstance($(myPhotoSwipe).attr('id'));
                    if (typeof photoSwipeInstance != "undefined" && photoSwipeInstance != null) {
                        photoSwipe.unsetActivateInstance(photoSwipeInstance);
                        photoSwipe.detatch(photoSwipeInstance);
                    }
                }
            });
        }
    });
于 2012-09-10T14:31:30.773 回答
0

我不确定这是否会帮助你,但是......

我将 PhotoSwipe 附加到具有类的页面gallery-page,然后将实际的 PhotoSwipe 实例附加到具有gallery包含图像的类的任何容器<a href="../path/image.jpg" rel="external">...</a>

我还给每个页面一个id。所以 index.html 有id="gallery1".

然后,在script.js我实际调用以将 PhotoSwipe 附加到.gallery类的文件中,我使用 if 语句(每页一个),如下所示:

// ..... bunch of JS, including PhotoSwipe core

// Create "exists" function for PhotoSwipe code
jQuery.fn.exists = function(){return this.length>0;}

// Create PhotoSwipe instance for a page that has id="gallery1"
if ($('#gallery1').exists()) {
        // Do something
        var myPhotoSwipe = $("#gallery1 .gallery a").photoSwipe({ 
            allowUserZoom: false,
            backButtonHideEnabled: true,
            enableMouseWheel: false, 
            enableKeyboard: false,
            cacheMode: Code.PhotoSwipe.Cache.Mode.aggressive,
            captionAndToolbarAutoHideDelay: 0,
            captionAndToolbarShowEmptyCaptions: false,
            jQueryMobile: true
        });
} // .... continue on for other page IDs

我对每个页面都这样做,根据我对每个特定页面的要求自定义 PhotoSwipe 设置。由于我创建了该exists函数,如果在一个 ID 与上一个不同的页面上,PhotoSwipe 实例将被删除,如果存在不同id="galleryN",则将附加其设置/图像。

我希望这会有所帮助......让我知道。

于 2012-09-06T13:03:46.897 回答