1

我对 LightGallery 插件 ( lightGallery - Git )有一点问题。我使用 jQueryMobile。

我的画廊位于特定页面上。当我到达这个页面时,它会请求一个远程服务器来获取一些图片。

然后我初始化 LightGallery。第一次没问题。

但是当我离开画廊页面并回来之后(有一个新的服务器请求),lightGallery 没有运行。

浏览器中没有错误,我显示了我的照片,但我无法像第一次那样单击它来运行 LightGallery。

我的代码:

HTML:

<div data-role="page" id="pageGallery" data-theme="a">
    <div data-role="content" class="center-body">
        <h3 class="nomGroupe"></h3><br/>
        <div class="demo-gallery">
            <ul id="lightgallery" class="list-unstyled row">
            </ul>
        </div>
    </div>
</div>

Javascript:

$( document ).on( "pagecontainerbeforeshow", function ( event, ui ) {
  var activePage = $.mobile.pageContainer.pagecontainer( "getActivePage" );
  if (activePage[0].id == "pageGallery" ) {
    $('#lightgallery').empty();
    $(".groupName").empty().append("group "+localStorage['groupName']);
    envoieRequete('http://myServer/', {'idGroup' : localStorage['idGroup'], 'token' : localStorage['token']}, 'post', function(output){
        if(output.group.photos.length === 0) {
            $("#lightgallery").append('<br/><p>Empty for Group : ' + localStorage['groupName']+'</p>');
        }
        else {
            for(i=0; i<output.group.photos.length; i++) {
                $('#lightgallery').append('<li class="col-xs-6 col-sm-4 col-md-3" data-responsive="http://myServer/'+localStorage['token']+'/'+localStorage['idGroup']+'/' + output.group.photos[i].id
                + '" data-src="http://myServer/'+localStorage['token']+'/'+localStorage['idGroup']+'/' + output.group.photos[i].id + '" data-sub-html="<h4>PhotoAlt</H4>"><a href=""><img class="img-responsive"\n\
                src="http://myServer/'+localStorage['token']+'/'+localStorage['idGroup']+'/' + output.group.photos[i].id + '"/></a></li>');
            }
        }
    });
  }
});

$(document).on("pagecontainershow", function () {
    var activePage = $.mobile.pageContainer.pagecontainer("getActivePage");
    var activePageId = activePage[0].id;
    switch (activePageId) {
        case 'pageGallery':
           $(document).on("tap", "#lightgallery li", function (){
                 $('#lightgallery').lightGallery({});
            });
    }
});
4

1 回答 1

0

您可能使用了错误的 html 标记。您可以查看以下代码以供参考。这是示例代码。

HTML

    <div class="row">
  <div class="large-12 columns">
    <ul class="small-block-grid-2 medium-block-grid-3" id="lightgallery">
      <li> <a class="item" href="img/alchemy_icon1.jpg"><img src="img/alchemy_icon1_th.jpg"></a>
      </li>
      <li> <a class="item" href="img/chandra1.jpg"><img src="img/chandra1-th.jpg"></a>
      </li>
      <li> <a class="item" href="img/Fish.jpg"><img src="img/Fish-th.jpg"></a>
      </li>
    </ul>
  </div>
</div>

Javascript

$("#lightgallery").lightGallery({
    selector: '.item'
});
于 2016-07-22T18:01:37.477 回答