【问题标题】:PhotoSwipe is not working on first time page loadPhotoSwipe 不适用于首次页面加载
【发布时间】:2013-07-24 13:23:38
【问题描述】:

我正在使用带有 jQ​​uery Mobile 的 Photoswipe 图库。第一个选择,单击时仅显示具有完整 URL 的图像,并且不适用于图库方式。当我返回并再次选择时,它工作正常。ps 在第一次失败/刷新页面后工作。

请检查下面的链接。这是我的移动网站。 http://w3qatar.info/aldarmobi

当我们检查链接属性> 列表中的任何属性> 查看更多照片...在此您可以找到缩略图。当我们首先单击缩略图时,它会加载没有画廊视图的原始图像。但是当我们返回并重试时,它会起作用。我正在使用 Opera 移动模拟器进行测试。带有 Mobile_jquery 主题的 Drupal 7。本站使用的是 Jquery mobile。

内部代码:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
  <link href="http://w3qatar.info/aldarmobi/sites/all/themes/mobile_jquery/photoswipe.css" type="text/css" rel="stylesheet" />  
  <script type="text/javascript" src="http://w3qatar.info/aldarmobi/sites/all/themes/mobile_jquery/lib/klass.min.js"></script>  
  <script type="text/javascript" src="http://w3qatar.info/aldarmobi/sites/all/themes/mobile_jquery/scripts/code.photoswipe.jquery-3.0.5.min.js"></script>

<script type="text/javascript">

(function(window, PhotoSwipe){

            document.addEventListener('DOMContentLoaded', function(){

        var
                options = {},
                instance = PhotoSwipe.attach( window.document.querySelectorAll('#gallery li a'), options );

        }, false);

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

    </script>

html部分:

<ul id="gallery" class="gallery">
<li><a href="imageurl1" rel="external"><img src="imageurl1" alt="image name1" /></a></li>
<li><a href="imageurl2" rel="external"><img src="imageurl2" alt="image name2" /></a></li>
<li><a href="imageurl3" rel="external"><img src="imageurl3" alt="image name3" /></a></li>
<li><a href="imageurl4" rel="external"><img src="imageurl4" alt="image name4" /></a></li>
</ul

你能帮帮我吗? 我想在 iPhone 设备和 android 手机上工作。

提前致谢。

哈里克里斯。

【问题讨论】:

  • 有时我发现新错误“未捕获的异常:Code.PhotoSwipe.createInstance:没有要传递的图像”。

标签: ios jquery-mobile mobile photoswipe


【解决方案1】:

我向您展示了您正在使用 jQuery 的代码,所以为什么不使用它来做所有事情。

你能像下面这样改变你的代码,看看它是否有效

(function(window, $, PhotoSwipe){

    $(document).ready(function(){

        $('div.p-img_more')
            .live('pageshow', function(e){

                var 
                    currentPage = $(e.target),
                    options = {},
                    photoSwipeInstance = $("ul.gallery a", e.target).photoSwipe(options,  currentPage.attr('id'));

                return true;

            })

            .live('pagehide', function(e){

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

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

                return true;

            });

    });

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

【讨论】:

  • 你好,我添加了上面的代码,但它在第一次加载或下一页刷新时不起作用。你能检查一下吗...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多