简体   繁体   English

在移动设备上的JQuery Mobile App中使用Photoswipe的空白页

[英]Blank Page with using Photoswipe in JQuery Mobile App on Mobile Devices

I got a problem with an Photoswipe Gallery. 我遇到了Photoswipe画廊的问题。 The problem that I'm encountering is, thatI click on a thumbnail, the full page and its controls, together with the image are loading, and then just a blank page is shown. 我遇到的问题是,我单击缩略图,整个页面及其控件以及图像都正在加载,然后仅显示空白页面。

This happens only on my mobile device (android 4.0.4), both in the standard browser and in chrome. 在标准浏览器和chrome中,这仅发生在我的移动设备(android 4.0.4)上。 But both firefox and chrome on my laptop are working fine. 但是笔记本电脑上的Firefox和Chrome都可以正常工作。

I attached the chrome remote debugger, and everything seems working fine. 我连接了chrome远程调试器,一切似乎都正常。

On chrome mobile the url-hash changes to #&ui-state=dialog in android standard browser, desktop chrome and firefox the hash doesn't alter and shows #pageid . 在chrome mobile上,URL哈希在android标准浏览器,台式机chrome和firefox中更改为#&ui-state=dialog ,哈希值不变,并显示#pageid

I tried to debugg the code, but I can't figuere out whats wrong. 我试图调试代码,但是我无法弄清楚出了什么问题。

The gallery markup is injected on a pagebeforechange event. 图库标记会在pagebeforechange事件中注入。 And Photoswipe is initialized as follows: 和Photoswipe初始化如下:

(function(window, $, PhotoSwipe){
    $(document).ready(function(){
        console.log('document ready')

        $('div.gallery-page').live('pageshow', function(e){
            console.log('pageshow');
            var currentPage = $(e.target);
            var options = { enableMouseWheel: false , enableKeyboard: false };                    
            var photoSwipeInstance = $("ul.gallery a", e.target).photoSwipe(options,  currentPage.attr('id'));
            console.log(e.target);

            return true; 
        }).live('pagehide', function(e){

            var currentPage = $(e.target),
                photoSwipeInstance = PhotoSwipe.getInstance(currentPage.attr('id'));

            if (typeof photoSwipeInstance != "undefined" && photoSwipeInstance != null) {
                PhotoSwipe.detatch(photoSwipeInstance);
            }

            return true;
        });
    });

}(window, window.jQuery, window.Code.PhotoSwipe)); 

any idea on why the page goes blank, only on mobile devices? 为什么只有在移动设备上页面才能空白?

//edit my workaround currently is doing that, on the pagebeforechange event: //在pagebeforechange事件上编辑当前的解决方法:

if(window.location.hash.search(/ui-state=dialog/) !== -1 ) {
    console.log('ui-state anomaly');
    e.preventDefault();
}

I had the same problem and found the solution at https://github.com/codecomputerlove/PhotoSwipe/issues/375 我遇到了同样的问题,并在https://github.com/codecomputerlove/PhotoSwipe/issues/375找到了解决方案

Also replaced all ".live" with ".on" in the initial code you posted above. 在上面发布的初始代码中,还用“ .on”替换了所有“ .live”。 Make sure your replace the "YourGalleryDiv" with your own div. 确保用自己的div替换“ YourGalleryDiv”。

$(document).bind('pagebeforechange', function(e) {
if ($('.ps-carousel').length) {
$('body').removeClass('ps-active');
$('#YourGalleryDiv').each(function(){
    var photoSwipe = window.Code.PhotoSwipe;
    var photoSwipeInstance = photoSwipe.getInstance($(this).attr('id'));
    if (typeof photoSwipeInstance != "undefined" && photoSwipeInstance != null) {
        photoSwipe.unsetActivateInstance(photoSwipeInstance);
    }
});
}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM