1

我无法运行插件 Lightgallery 哈希。我希望在同一页面上有两个画廊,单击一个按钮应该显示另一个。如果我没记错的话,插件应该这样做。

我添加了这个 HTML 结构:

<div id="hash">
<a href="img/img_port/reportage/img-1.jpg">
    <img src="img/img_port/reportage/thumb-1.jpg" />
</a>
<a href="img/img_port/reportage/img-2.jpg">
    <img src="img/img_port/reportage/thumb-2.jpg" />
</a>
<a href="img/img_port/reportage/img-3.jpg">
    <img src="img/img_port/reportage/thumb-3.jpg" />
</a>
<a href="img/img_port/reportage/img-4.jpg">
    <img src="img/img_port/reportage/thumb-4.jpg" />
</a>

<div id="hash2">   
<a href="img/img_port/reportage/img-1.jpg">
    <img src="img/img_port/reportage/thumb-1.jpg" />
</a>
<a href="img/img_port/reportage/img-2.jpg">
    <img src="img/img_port/reportage/thumb-2.jpg" />
</a>
<a href="img/img_port/reportage/img-3.jpg">
    <img src="img/img_port/reportage/thumb-3.jpg" />
</a>
<a href="img/img_port/reportage/img-4.jpg">
    <img src="img/img_port/reportage/thumb-4.jpg" />
</a>

而这个Javascript:

<script type="text/javascript">
        $(document).ready(function() {
            $("#hash").lightGallery({
                download: false,
                counter: false,
                hash: true;
                galleryId: 1
                });
            $("#hash2").lightGallery({
                download: false,
                counter: false,
                hash: true;
                galleryId: 2
                    });
            });
    </script>

这是正确的还是有什么问题?

4

2 回答 2

1
<script type="text/javascript">
    $(document).ready(function() {
        $("#hash").lightGallery({
            download: false,
            counter: false,
            hash: true,  /*Here is the error.*/
            galleryId: 1
            });
        $("#hash2").lightGallery({
            download: false,
            counter: false,
            hash: true,/*Here is the error.*/
            galleryId: 2
                });
        });
</script>
于 2016-02-27T16:13:25.283 回答
0

首先,您应该通过类而不是 id 来识别您的画廊。

<div class="lightgallery">
    <a href="img/img_port/reportage/img-1.jpg">
        <img src="img/img_port/reportage/thumb-1.jpg" />
    </a>
    <a href="img/img_port/reportage/img-2.jpg">
        <img src="img/img_port/reportage/thumb-2.jpg" />
    </a>
</div>

<div class="lightgallery">   
    <a href="img/img_port/reportage/img-1.jpg">
        <img src="img/img_port/reportage/thumb-1.jpg" />
    </a>
    <a href="img/img_port/reportage/img-2.jpg">
        <img src="img/img_port/reportage/thumb-2.jpg" />
    </a>
</div>

然后用特定的类循环每个并启动 lig​​htGallery()

$('.lightgallery').each(function (index) {
    $('#' + this.id).lightGallery({
        share: false,
        galleryId: index
    });
})
于 2019-03-13T23:39:58.097 回答