【问题标题】:Photoswipe with Justified Gallery使用 Justified Gallery 进行照片滑动
【发布时间】:2016-10-10 13:44:28
【问题描述】:

我在我的 Rails 项目中成功设置了 PhotoswipeJustified Gallery。他们两个单独工作都很好,但我很难让他们一起工作。

在我当前的(默认)设置中,Photoswipe 期望标签层次结构如下:

<figure>
  <a href="...>
    <img src=".../>
  </a>

Justified Gallery 默认配置为识别具有任意数量 &lt;a&gt; 标记的容器,其中嵌套了 &lt;img&gt; 标记,如下所示:

<div id="mygallery" >
    <a href="...>
        <img src=".../>
    </a>
    <a href="...>
        <img src=".../>
    </a>
    <!-- other images... -->
</div>

所以我需要让 Justified Gallery 识别 &lt;figure&gt; 标签。在他们的文档中,它说您只需添加以下选项:

selector: 'figure, div:not(.spinner)'

这部分似乎工作正常,但也提到有必要扩展 CSS 规则,这就是我卡住的地方。我希望在所有或部分&gt; a 选择器前面加上&gt; 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;
}

我已经玩了很长时间了,但我无法完成这项工作。我也无法在网上找到一个很好的例子。

有没有人做过这个或者知道怎么解决?

【问题讨论】:

    标签: css ruby-on-rails image-gallery photoswipe


    【解决方案1】:

    我设法通过使用以下方法解决了这个问题:

    selector: 'a, figure:not(.spinner)'
    

    在选项中,并用figure 替换css 中的所有div 选择器。所以

    .justified-gallery > div > img,
    

    会变成:

    .justified-gallery > figure > img,
    

    【讨论】:

      【解决方案2】:

      使用 Justified Gallery v3.7.0 和 PhotoSwipe v4.1.3 只需将默认选择器替换为

      'figure, > div:not(.spinner)'
      

      因此,对于&lt;div id="mygallery"&gt; 一个得到:

      $('#mygallery').justifiedGallery({
          selector: 'figure, > div:not(.spinner)'
      }).on('jg.complete', function () {
          initPhotoSwipeFromDOM('#mygallery');
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多