Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
分离ajax调用问题期间创建的Photosweep实例_Ajax_Jquery_Jquery Mobile_Photoswipe - Fatal编程技术网

分离ajax调用问题期间创建的Photosweep实例

分离ajax调用问题期间创建的Photosweep实例,ajax,jquery,jquery-mobile,photoswipe,Ajax,Jquery,Jquery Mobile,Photoswipe,图像通过$绘制。ajax 然后在$内创建Photosweep实例。ajax 当用户单击浏览器的“后退”按钮时,尝试分离Photosweep实例,但无法分离 有人知道克服这一问题的任何可能的解决方案吗?我不确定这是否对你有帮助,但是 我将Photosweep附加到一个带有类图库页面的页面上,然后将实际的Photosweep实例附加到任何带有类图库的容器上,该容器包含带有的图像 我还为每个页面提供一个id。因此index.html具有id=“gallery1” 然后,在我的script.js文件中,

图像通过
$绘制。ajax

然后在
$内创建Photosweep实例。ajax

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


有人知道克服这一问题的任何可能的解决方案吗?

我不确定这是否对你有帮助,但是

我将Photosweep附加到一个带有类
图库页面
的页面上,然后将实际的Photosweep实例附加到任何带有类
图库
的容器上,该容器包含带有
的图像

我还为每个页面提供一个id。因此index.html具有
id=“gallery1”

然后,在我的
script.js
文件中,我实际调用该文件将Photoswip附加到
.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
我对每个页面都这样做,根据我对每个特定页面的要求定制Photosweep设置。由于我创建了
exists
函数,如果在ID与上一个不同的页面上,Photosweep实例将被删除,如果存在不同的
ID=“galleryN”
,则将附加该页面的设置/图像


我希望这有助于。。。让我知道。

终于找到了解决方案。请参阅下文

$.ajax({ url: URL_TO_GET_JSON, success: function(json, status) { var p = []; $.each(json, function(a,b){ //DRAW IMAGES HERE. }); $('.gallery').html(photo.join('')); // CREATE INSTANCES HERE var myPhotoSwipe = $(".gallery a").photoSwipe({ enableMouseWheel: false, }) /********** UNSET INSTANCES HERE *****************/ $(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); } } }); } }); $.ajax({ url:url\u到\u获取\u JSON, 成功:函数(json,状态){ var p=[]; $.each(json,函数(a,b){ //在此绘制图像。 }); $('.gallery').html(photo.join(''); //在这里创建实例 var myphotosweep=$(“.gallery a”).photosweep({ enableMouseWheel:错误, }) /**********在此处取消设置实例*****************/ $(文档).bind('pagebeforechange',函数(e){ 如果($('.ps carousel')。长度){ $('body').removeClass('ps-active'); var photosweep=window.Code.photosweep; var photoSwipeInstance=photoSwipe.getInstance($(myPhotoSwipe.attr('id')); if(类型为PhotosweepInstance!=“未定义”&&PhotosweepInstance!=null){ 取消激活实例(Photosweep实例); Photosweep.depatch(Photosweep实例); } } }); } });
如何连接Photosweep实例?通过画廊课程?或者…?我在$.ajax()方法中执行了这个var myphotosweep=$(“.gallery a”).photosweep({enablemouseheel:false,})。感谢您的帮助,我已经找到了删除它的方法。请看看我的解决方案。