在blueimp库中添加描述 [英] Adding descriptions inside a blueimp gallery

查看:55
本文介绍了在blueimp库中添加描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 BlueImp图库为我的图片添加灯箱画廊。因此,当您单击图像缩略图时,它会启动一个带有更大版本图像等的灯箱。

I am using a BlueImp Gallery to add lightboxes to my image gallery. So, when you click on an image thumbnail, it launches a lightbox with a larger version of the image etc.

我还想添加一些描述性文本和一个按钮到灯箱的每张幻灯片,但我无法使它工作。它不会显示我添加的占位符描述。

I also want to add in some descriptive text and a button to each slide of the lightbox, but I am having trouble making it work. It won't show the placeholder descriptions that I have added in.

这是我到目前为止的内容;

Here's what I have so far;

HTML:

<div id="blueimp-gallery" class="blueimp-gallery">
    <!-- The container for the modal slides -->
    <div class="slides"></div>
    <!-- Controls for the borderless lightbox -->
    <h3 class="title"></h3>
    <p class="description"></p>
    <a class="prev">‹</a>
    <a class="next">›</a>
    <a class="close">×</a>
    <a class="play-pause"></a>
    <ol class="indicator"></ol>

    <div class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" aria-hidden="true">&times;</button>
                    <h4 class="modal-title"></h4>
                </div>
                <div class="modal-body next"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left prev">
                        <i class="glyphicon glyphicon-chevron-left"></i>
                        Previous
                    </button>
                    <button type="button" class="btn btn-primary next">
                        Next
                        <i class="glyphicon glyphicon-chevron-right"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="links">

<div class="row prints">
  <div class="col-md-4">
    <div class="thumbnail">    
      <div class="caption">
        <a href="http://farm3.staticflickr.com/2843/10406026526_4cd1b56391.jpg" title="Ballooning" data-description="This is a banana." data-gallery>
          <img src="http://farm8.staticflickr.com/7389/10404414563_0914b69e0e.jpg" alt="Ballooning">
        </a>
        <h3>Ballooning</h3>
        <p>from $18.00</p>
        <p><a href="#" class="btn btn-YLP">Find out more</a></p>
      </div>
   </div>
  </div>  
  <div class="col-md-4">
    <div class="thumbnail">    
      <div class="caption">  
        <a href="http://farm6.staticflickr.com/5547/10406009404_c197c2221b.jpg" title="Clearing" data-description="This is a apple." data-gallery>
            <img src="http://farm6.staticflickr.com/5490/10404414523_745ea3065d.jpg" alt="Clearing">
        </a> 
        <h3>Clearing</h3>
        <p>from $18.00</p>
        <p><a href="#" class="btn btn-YLP">Find out more</a></p>
      </div>
   </div>
  </div>
  <div class="col-md-4">
    <div class="thumbnail">    
      <div class="caption">              
        <a href="http://farm6.staticflickr.com/5510/10406026066_7f95a075ee.jpg" title="Sky/Sea" data-description="This is a cherry." data-gallery>
            <img src="http://farm4.staticflickr.com/3769/10404249505_d767f7c420.jpg" alt="Sky/Sea">
        </a>
        <h3>Sky/Sea</h3>
        <p>from $18.00</p>
        <p><a href="#" class="btn btn-YLP">Find out more</a></p>
      </div>
   </div>
  </div>  
  <div class="col-md-4">
    <div class="thumbnail">    
      <div class="caption">          
        <a href="http://farm4.staticflickr.com/3678/10406009004_5c625e2028.jpg" title="Lights" data-description="This is a grapefruit." data-gallery>
            <img src="http://farm3.staticflickr.com/2814/10404249395_9e4cae5bc7.jpg" alt="Lights">
        </a>
        <h3>Lights</h3>
        <p>from $18.00</p>
        <p><a href="#" class="btn btn-YLP">Find out more</a></p>
      </div>
   </div>
  </div>  
  <div class="col-md-4">
    <div class="thumbnail">    
      <div class="caption">          
        <a href="http://farm6.staticflickr.com/5538/10406019875_8424fbee11.jpg" title="Silhouettes" data-description="This is a orange." data-gallery>
            <img src="http://farm8.staticflickr.com/7343/10404255766_d808d1902d.jpg" alt="Silhouettes">
        </a>
        <h3>Silhouettes</h3>
        <p>from $18.00</p>
        <p><a href="#" class="btn btn-YLP">Find out more</a></p>
      </div>
   </div>
  </div>   
  <div class="col-md-4">
    <div class="thumbnail">    
      <div class="caption">         
        <a href="http://farm4.staticflickr.com/3682/10406009134_3b666324ff.jpg" title="Sway" data-description="This is a kiwi." data-gallery>
            <img src="http://farm6.staticflickr.com/5516/10404249545_7efb481042.jpg" alt="Sway">
        </a>
        <h3>Sway</h3>
        <p>from $18.00</p>
        <p><a href="#" class="btn btn-YLP">Find out more</a></p>
      </div>
   </div>
  </div>  
  <div class="col-md-4">
    <div class="thumbnail">    
      <div class="caption">          
        <a href="http://farm8.staticflickr.com/7425/10406019935_1def1e0c09.jpg" title="Sunset" data-description="This is a grape." data-gallery>
            <img src="http://farm3.staticflickr.com/2810/10404249465_0124b7f3e5.jpg" alt="Sunset">
        </a>
        <h3>Sunset</h3>
        <p>from $18.00</p>
        <p><a href="#" class="btn btn-YLP">Find out more</a></p>
      </div>
   </div>
  </div>  
  <div class="col-md-4">
    <div class="thumbnail">    
      <div class="caption">          
        <a href="http://farm6.staticflickr.com/5532/10406009324_4cd1b56391.jpg" title="Lighthouse" data-description="This is a strawberry." data-gallery>
            <img src="http://farm6.staticflickr.com/5543/10404240054_6261498220.jpg" alt="Lighthouse">
        </a>
        <h3>Lighthouse</h3>
        <p>from $18.00</p>
        <p><a href="#" class="btn btn-YLP">Find out more</a></p>
      </div>
   </div>
  </div> 
  <div class="col-md-4">
    <div class="thumbnail">    
      <div class="caption">           
        <a href="http://farm4.staticflickr.com/3747/10406026506_6a4dbf2df0.jpg" title="Slabs"data-description="This is a pineapple." data-gallery>
            <img src="http://farm8.staticflickr.com/7345/10404249655_7512bf6565.jpg" alt="Slabs">
        </a>
        <h3>Slabs</h3>
        <p>from $18.00</p>
        <p><a href="#" class="btn btn-YLP">Find out more</a></p>
      </div>
   </div>
  </div>        
</div>
</div>

CSS:

.blueimp-gallery > .description {
  position: absolute;
  top: 30px;
  left: 15px;
  color: red;
  display: none;
}

.blueimp-gallery-controls > .description {
  display: block;
}

JS:

blueimp.Gallery(
    document.getElementById('links'),
    {
        onslide: function (index, slide) {
            var text = this.list[index].getAttribute('data-description'),
                node = this.container.find('.description');
            node.empty();
            if (text) {
                node[0].appendChild(document.createTextNode(text));
            }
        }
    }
);

在我的身体中(gallery.js是我添加上述JS的文件):

And in my body (gallery.js is the file where I've added the above JS):

  <script src="//code.jquery.com/jquery.js"></script>
  <script src="js/bootstrap.min.js"></script>
  <script src="lib/fancybox/jquery.fancybox.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script src="http://blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js"></script>
  <script src="js/bootstrap-image-gallery.min.js"></script>
  <script src="js/gallery.js"></script>

任何关于我出错的地方都会非常感激!

Any pointers on where I've gone wrong would be much appreciated!

推荐答案

您可以在 a 元素上传递任何所需数据,然后将其显示在库中。
我花了很多时间试图找到答案,所以我会留在这里。
以下是一个示例:

You can pass any needed data on a element, and then display it in the gallery. I spend a lot of time trying to find an answer, so I'll leave it here. Here is an example:

HTML:

<div id="blueimp-gallery" class="blueimp-gallery">
    <div class="slides"></div>
    <h3 class="title"></h3>
    <p class="description"></p>
    <p class="example"></p>
    ...
</div>
------
<div id="links">
    <a href="images/banana.jpg" title="Banana" data-description="This is a banana." data-example="Additional data">Banana</a>
    <a href="images/apple.jpg" title="Apple" data-description="This is an apple." data-example="Additional data">Apple</a>
</div>

JS:

document.getElementById('links').onclick = function (event) {
  event = event || window.event;
  var target = event.target || event.srcElement,
    link = target.src ? target.parentNode : target,
    options = {
      index: link, event: event,
      onslide: function (index, slide) {

        self = this;
        var initializeAdditional = function (index, data, klass, self) {
          var text = self.list[index].getAttribute(data),
            node = self.container.find(klass);
          node.empty();
          if (text) {
            node[0].appendChild(document.createTextNode(text));
          }
        };
        initializeAdditional(index, 'data-description', '.description', self);
        initializeAdditional(index, 'data-example', '.example', self);
      }
    },
    links = this.getElementsByTagName('a');
  blueimp.Gallery(links, options);
};

CSS:
您可以使用 .scss 重构它,但它只是例如

CSS: You can use .scss to refactor it, but it's just for example

.blueimp-gallery > .description, .blueimp-gallery > .example {
  position: absolute;
  top: 30px;
  left: 15px;
  color: #fff;
  display: none;
}
.blueimp-gallery-controls > .description, .blueimp-gallery-controls > .example {
  display: block;
}

这篇关于在blueimp库中添加描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆