简体   繁体   English

Lightgallery不起作用(分别使用翡翠和加载页面)

[英]Lightgallery not working (using jade and loading page separately)

I am relatively new to javascript and I cannot figure out what I might be doing wrong here to implement lightgallery in my code. 我对javascript还是比较陌生,在这里我无法弄清楚我在代码中实现lightgallery的错误。

I included all stylesheets (in the header) and relevant scripts. 我包括了所有样式表(在标题中)和相关的脚本。 Here is what part of my head and body looks like. 这是我头部和身体的一部分。

head
    link(rel='stylesheet',  href='nodescripts/css/lightgallery.css')
body
    //jade block for pages
    block content
    script(src='/nodescripts/jquery.min.js')
    script(src='/nodescripts/bootstrap.min.js')
    script(src='/nodescripts/wow.min.js')

    //gallery
    script(src='/nodescripts/js/lightgallery.js')
    script(src='nodescripts/js/lg-thumbnail.min.js')
    script(src='nodescripts/js/lg-fullscreen.min.js')
    script(src='https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js')
    script(src="/javascripts/loadPages.js")

    script.    
        //loads main menu page (function from loadPages.js)
        loadIndex()

    script.
        $(document).ready(function() {
            $("#lightgallery").lightGallery({
                selector: '.item'
           }); 
        });

The loadIndex function in loadPages.js (goes to server side, works without a pb) loadPages.js中的loadIndex函数(转到服务器端,不带pb即可工作)

function loadIndex (){
    $.get('/Index', function(content){
        $("#upperContainer").css('background-image', 'url(/images/SF-background.jpg)');
        $('#mainContainer').html(content);
    });
}

And here is the images markup I use: 这是我使用的图像标记:

#photoRow.row
    ul#lightgallery 
        li
            a.item(href='/images/s-gallery/big(1).jpg')
                img(src='/images/s-gallery/small/small(1).jpg')
        li
            a.item(href='/images/s-gallery/big(2).jpg')
                img(src='/images/s-gallery/small/small(2).jpg')
        li
            a.item(href='/images/s-gallery/big(3).jpg')
                img(src='/images/s-gallery/small/small(3).jpg')

The lightgallery is supposed to appear in the index page, which is loaded by the loadIndex() function (I am using a navbar with several pages). lightgallery应该出现在由loadIndex()函数加载的索引页面中(我正在使用具有多个页面的导航栏)。 Am I not doing the lightgallery call properly? 我没有正确地拨打灯廊电话吗? Is my $(document).ready(...) happening at the same time than my index page is being loaded? 我的$ {document).ready(...)是否在加载索引页的同时发生? (Though I know that scripts are technically called synchronously). (尽管我知道脚本在技术上是同步调用的)。

Basically my images show no effect at all and remain a non styled list.. Can someone help? 基本上,我的图像完全不显示效果,并且仍然是非样式列表。

Call lightGallery from the loadIndex function as below. loadIndex函数调用lightGallery ,如下所示。

Because it is an AJAX function the callback is executed after the document ready function is fired so the plugin could not find any elements to work with. 由于它是AJAX函数,因此在触发文档就绪函数后将执行回调,因此插件找不到任何要使用的元素。

function loadIndex (){
    $.get('/Index', function(content){
        $("#upperContainer").css('background-image', 'url(/images/SF-background.jpg)');
        $('#mainContainer').html(content);
        $("#lightgallery").lightGallery({
            selector: '.item'
        });
    });
}

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

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