简体   繁体   English

Lightbox2没有启动

[英]Lightbox2 not initiating

Ok so what I thought would take me few minutes to implement has now taken up over an hour of my time and I'm just completely puzzled. 好的,我认为需要几分钟才能完成的工作现在占用了我一个多小时的时间,我只是完全不解。

I downloaded lightbox2 , followed the instructions; 我按照说明下载了lightbox2 ; embedding their CSS and JS in the head of my index.html 将他们的CSS和JS嵌入我的index.html的头部

<link href="lightbox/lightbox.css" rel="stylesheet">
<script src="lightbox/lightbox-plus-jquery.js"></script>

I am only testing it on localhost if that makes any difference. 我只在localhost上测试它,如果这有任何区别。 The paths are set correctly 100% and so are the paths to the 4 images the CSS requires.. 路径设置正确100%,CSS所需的4个图像的路径也是如此。

Now in my body I am using the a href with the data-lightbox attribute like this 现在,在我的身体中,我正在使用带有data-lightbox属性的href

<a class="example-image-link" href="gallery/i1.jpg" data-lightbox="group" data-title="Optional caption.">
    <img class="example-image" src="gallery/i1.jpg" alt="desc">
</a>
<a class="example-image-link" href="gallery/i2.jpg" data-lightbox="group" data-title="Optional caption.">
    <img class="example-image" src="gallery/i2.jpg" alt="desc">
</a>

There is nothing else on the page so the result looks like this: 页面上没有其他内容,因此结果如下所示: 结果

The issue is that when I click one of the images, instead of the lightbox popping up the image just opens in a fullscreen tab. 问题在于,当我单击其中一个图像时,弹出的图像只会在全屏选项卡中打开,而不是灯箱弹出。 It's like the lightbox is not working at all, and it just follows the a href to the image.. I even tried JSFiddle and loaded the same CSS and JS as external resources and it's doing the exact same thing. 就像灯箱根本不工作一样,它只是跟随图像a href 。我甚至尝试了JSFiddle并加载了与外部资源相同的CSS和JS,它正在做同样的事情。 See for yourselves -> JSFIDDLE 看看你自己 - > JSFIDDLE

I am open to any ideas.. Really don't understand what am I missing. 我对任何想法持开放态度。真的不明白我错过了什么。

You should move the <script src="lightbox/lightbox-plus-jquery.js"></script> bit to the end of your body tag in the HTML, instead of the head . 您应该将<script src="lightbox/lightbox-plus-jquery.js"></script>位移到HTML中的body标记的末尾,而不是head The problem is that if the script is in the head, it will run before the images are ready to be parsed by the library. 问题是如果脚本在头部,它将在图像准备好被库解析之前运行。

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

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