Photoswipe中的第一个选择不起作用

时间:2012-09-24 11:03:18

标签: jquery-mobile photoswipe

我正在使用带有jQuery Mobile的Photoswipe图库。单击/点击时的第一个选择仅显示具有完整URL的图像,并且不适用于图库方式。当我回去再次选择时,它工作正常。

任何人都可以告诉我如何解决这个问题?

干杯!

1 个答案:

答案 0 :(得分:1)

当用户使用链接照片直接进入photoswipe画廊页面时,未初始化。例如,即使使用直接链接进行官方演示也会出现此问题。链接:http://www.photoswipe.com/latest/examples/04-jquery-mobile.html#Gallery1

尝试在pageshow之前添加photoswipe附加pagehidejquery-mobile.js事件处理程序的脚本。如果处理程序在第一次用户访问页面后不会被触发,则会被附加。

<script type="text/javascript" src="code.photoswipe-3.0.5.min.js"></script>
<script type="text/javascript">
    (function(window, $, PhotoSwipe){

        $(document).ready(function(){
            $('div.gallery-page')
                .live('pageshow', function(e){
                    if( $('ul.gallery', e.target).length > 0 ){
                        var 
                            currentPage = $(e.target),
                            options = {},
                            photoSwipeInstance = $("ul.gallery a", e.target).photoSwipe(options,  currentPage.attr('id'));

                            return true;
                    }
                })

                .live('pagehide', function(e){
                    if( $('ul.gallery', e.target).length > 0 ){
                        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));

</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
相关问题