灯箱不适用于 Rails,即使页面加载文档已准备好在代码中

Lightbox not working with Rails, even when document on page load ready is in the codes

本文关键字:文档 加载 准备好 代码 适用于 不适用 Rails      更新时间:2023-09-26

我正在使用带有Rails的Lightbox。

我已经用灯箱加 jquery.js 文件做了大家在堆栈溢出上建议的事情,以停止涡轮链接。 即

var ready;
ready = function() {
<the downloaded codes>    
};
$(document).ready(ready);
$(document).on('page:load', ready);

但是我的图片库仍然无法正常工作,不要认为我的代码是错误的,因为我的所有其他 JS 文件都可以使用上述代码?

我的网页代码:

   <a class="example-image-link" href="http://lokeshdhakar.com/projects/lightbox2/images/image-3.jpg" data-lightbox="example-set" data-title="Click the right half of the image to move forward."><img class="example-image" src="http://lokeshdhakar.com/projects/lightbox2/images/thumb-3.jpg" alt=""/></a>
    <a class="example-image-link" href="http://lokeshdhakar.com/projects/lightbox2/images/image-4.jpg" data-lightbox="example-set" data-title="Or press the right arrow on your keyboard."><img class="example-image" src="http://lokeshdhakar.com/projects/lightbox2/images/thumb-4.jpg" alt="" /></a>
    <a class="example-image-link" href="http://lokeshdhakar.com/projects/lightbox2/images/image-5.jpg" data-lightbox="example-set" data-title="The next image in the set is preloaded as you're viewing."><img class="example-image" src="http://lokeshdhakar.com/projects/lightbox2/images/thumb-5.jpg" alt="" /></a>
    <a class="example-image-link" href="http://lokeshdhakar.com/projects/lightbox2/images/image-6.jpg" data-lightbox="example-set" data-title="Click anywhere outside the image or the X to the right to close."><img class="example-image" src="http://lokeshdhakar.com/projects/lightbox2/images/thumb-6.jpg" alt="" /></a>

CSS代码是从站点下载的默认代码。

以前有人成功使用过带导轨的灯箱吗?或者可以帮助我破解这个案子?

提前谢谢。

我遇到了同样的问题。这不是轨道问题。

你应该把

<script src="lightbox/lightbox-plus-jquery.js"></script>

(或等效项)到 HTML 中正文标签的末尾,而不是头部。问题是,如果脚本在头部,它将在图像准备好被库解析之前运行。