LightGallery与JqueryMobile

时间:2016-07-22 17:52:03

标签: html jquery-mobile lightgallery

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

我的图库位于特定页面上。当我到达此页面时,它将请求远程服务器获取一些照片。

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

当我离开Gallery Page并在之后回来(对服务器有新的请求)时,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>

Javscript:

$( 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({});
            });
    }
});

1 个答案:

答案 0 :(得分: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'
});