html - 灯箱标题标题不起作用

标签 html css lightbox title caption

我是一个真正的新手,正在尝试使用网页模板来设计我自己的网站。

我有一个基本的灯箱画廊,一切正常,但无论我尝试过什么,我都无法在画廊图片(而不是缩略图)上显示标题。

这是带有单个图库元素的 html 代码片段:

<div class="gallery-item">
  <div class="image">
   <div class="overlay">
    <a href="img/gallery/gallery-item1.jpg" data-rel="lightbox" data-title="explanation of image goes in here"></a>
    </div>
    <img src="img/gallery/gallery-item1.jpg" alt="image 4">
   </div>

我试过使用 title="caption"而不是 data-title ="caption",但没有成功。这是灯箱的 CSS:

#lightbox {
cursor: pointer;
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: black;
/* IE Fallback (Solid Colour) */
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAIElEQVQ4T2NkYGDYDMRkA8ZRAxhGw4BhNAyA+WAYpAMAIFgLQfO9BoEAAAAASUVORK5CYII=);
background: rgba(0, 0, 0, 0.7);
-webkit-filter: none !important;
}

#lightbox img {
display: block;
position: absolute;
border: 5px solid #fff;
box-shadow: 0 0 20px #000;
border-radius: 1px;
}

body.blurred > * {
-webkit-filter: blur(2px);
-webkit-transform: translate3d(0, 0, 0);
}

.lightbox-loading {
background: url(../img/loading.gif) center center no-repeat;
width: 31px;
height: 31px;
margin: -16px 0 0 -16px;
position: absolute;
top: 48%;
left: 50%;
}  

.lightbox-caption {
display: none;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
text-align: center;
z-index: 1000;
background: #000;
background: rgba(0, 0, 0, 0.7);
}

.lightbox-caption p {
margin: 0 auto;
max-width: 70%;
display: inline-block;
*display: inline;
*zoom: 1;
padding: 10px;
color: #fff;
font-size: 12px;
line-height: 18px;
}

.lightbox-button {
position: absolute;
z-index: 9999;
background: no-repeat center center;
width: 32px;
height: 32px;
opacity: 0.4;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
transition: all 0.3s;
}

.lightbox-button:hover,
.lightbox-button:focus {
opacity: 1;
-webkit-transform: scale(1.4);
-moz-transform: scale(1.4);
-ms-transform: scale(1.4);
transform: scale(1.4);
}

.lightbox-close {
right: 30px;
top: 30px;
background-image: url("../img/close.png");
}

.lightbox-next {
right: 30px;
top: 48%;
background-image: url("../img/next.png");
}

.lightbox-previous {
left: 30px;
top: 48%;
background-image: url("../img/previous.png");
}

欢迎任何提示/帮助。谢谢

最佳答案

标题由 anchor 标记中的“data-caption”属性加载。

您的 anchor 标签目前看起来像这样:

<a href="img/gallery/gallery-item1.jpg" data-rel="lightbox" class="fa fa-expand"></a>

您需要像这样插入标题:

<a href="images/gallery/gallery-item1.jpg" data-caption="caption here" data-rel="lightbox" class="fa fa-expand"></a>

为了您自己的兴趣,如果您查看源文件中的 javascript,您将看到以下几行:

setCaption: function () {
                var caption = $(plugin.current).data('caption');
                if(!!caption && caption.length > 0) {
                    plugin.caption.fadeIn();
                    $('p', plugin.caption).text(caption);
                }else{
                    plugin.caption.hide();
                }
            },

第二行说:

var caption = $(plugin.current).data('caption');

这是将标题设置为您在 data-caption 字段中的任何文本。如果它说 .data('title'),那么您将使用 data-title = "my caption"

希望对您有所帮助。

关于html - 灯箱标题标题不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41162517/

相关文章:

html - 有没有办法在 HTML/CSS 中的每行文本的开头重复引号?

css - 在 less 中连接多个选择器

javascript - 如何制作灯箱? : concept

javascript - 延迟加载破坏了灯箱

java - 未找到 JSF 2.2 Facelet taglib 的直通属性

html - 将缩略图宽度与其父图像对齐

html - 右边的 4 张图片作为侧边栏

css - 带有 css 图像的透明或不透明背景

html - UIWebView 移动站点宽度

javascript - 如何创建一个按钮来选择下一张图片,获取其 src 并将其替换为灯箱?