我在Rails项目中成功设置了Photoswipe和Justified Gallery。他们两个都很好地独自工作,但我很难让他们一起工作。
在我当前的(默认)设置中,Photoswipe期望标签层次结构如下:
<figure>
<a href="...>
<img src=".../>
</a>
默认情况下, Justified Gallery配置为识别具有任意数量的<a>
标记的容器,其中包含嵌套的<img>
标记,如下所示:
<div id="mygallery" >
<a href="...>
<img src=".../>
</a>
<a href="...>
<img src=".../>
</a>
<!-- other images... -->
</div>
所以我需要让Justified Gallery识别出<figure>
标签。在他们的文档中,它说你只需要添加以下选项:
selector: 'figure, div:not(.spinner)'
这部分似乎工作正常,但也提到有必要扩展CSS规则,这就是我被困的地方。我希望在> a
选择器之前添加> figure
选择器的前提是应该完成这项工作但不是。这些是Justified Gallery附带的规则:
.justified-gallery {
width: 100%;
position: relative;
overflow: hidden;
}
.justified-gallery > a,
.justified-gallery > div {
position: absolute;
display: inline-block;
overflow: hidden;
opacity: 0;
filter: alpha(opacity=0);
/* IE8 or Earlier */
}
.justified-gallery > a > img,
.justified-gallery > div > img,
.justified-gallery > a > a > img,
.justified-gallery > div > a > img {
position: absolute;
top: 50%;
left: 50%;
margin: 0;
padding: 0;
border: none;
}
.justified-gallery > a > .caption,
.justified-gallery > div > .caption {
display: none;
position: absolute;
bottom: 0;
padding: 5px;
background-color: #000000;
left: 0;
right: 0;
margin: 0;
color: white;
font-size: 12px;
font-weight: 300;
font-family: sans-serif;
}
.justified-gallery > a > .caption.caption-visible,
.justified-gallery > div > .caption.caption-visible {
display: initial;
opacity: 0.7;
filter: "alpha(opacity=70)";
/* IE8 or Earlier */
-webkit-animation: justified-gallery-show-caption-animation 500ms 0 ease;
-moz-animation: justified-gallery-show-caption-animation 500ms 0 ease;
-ms-animation: justified-gallery-show-caption-animation 500ms 0 ease;
}
.justified-gallery > .entry-visible {
opacity: 1.0;
filter: alpha(opacity=100);
/* IE8 or Earlier */
-webkit-animation: justified-gallery-show-entry-animation 500ms 0 ease;
-moz-animation: justified-gallery-show-entry-animation 500ms 0 ease;
-ms-animation: justified-gallery-show-entry-animation 500ms 0 ease;
}
.justified-gallery > .jg-filtered {
display: none;
}
.justified-gallery > .spinner {
position: absolute;
bottom: 0;
margin-left: -24px;
padding: 10px 0 10px 0;
left: 50%;
opacity: initial;
filter: initial;
overflow: initial;
}
.justified-gallery > .spinner > span {
display: inline-block;
opacity: 0;
filter: alpha(opacity=0);
/* IE8 or Earlier */
width: 8px;
height: 8px;
margin: 0 4px 0 4px;
background-color: #000;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;
}
我已经玩了很长一段时间,但是我无法做到这一点。我也无法在网上找到一个很好的例子。
之前有人这样做过或者知道如何解决它?
答案 0 :(得分:0)
我设法通过使用以下方法解决了这个问题:
selector: 'a, figure:not(.spinner)'
在选项中,并使用div
替换css中的所有figure
选择器。所以
.justified-gallery > div > img,
会变成:
.justified-gallery > figure > img,
答案 1 :(得分:0)
使用Justified Gallery v3.7.0和PhotoSwipe v4.1.3只需将默认选择器替换为
'figure, > div:not(.spinner)'
因此,<div id="mygallery">
可获得:
$('#mygallery').justifiedGallery({
selector: 'figure, > div:not(.spinner)'
}).on('jg.complete', function () {
initPhotoSwipeFromDOM('#mygallery');
});