简体   繁体   English

Blueimp Bootstrap-Image-Gallery直接在页面加载时初始化为灯箱/以编程方式打开灯箱

[英]Blueimp Bootstrap-Image-Gallery initialize directly to lightbox / open lightbox programmatically on page load

I'm using Blueimp Bootstrap-Image-Gallery: 我正在使用Blueimp Bootstrap-Image-Gallery:
https://github.com/blueimp/Bootstrap-Image-Gallery/blob/master/README.md https://github.com/blueimp/Bootstrap-Image-Gallery/blob/master/README.md

Which is an extension of Blueimp Gallery: https://github.com/blueimp/Gallery/blob/master/README.md 这是Blueimp Gallery的扩展: https : //github.com/blueimp/Gallery/blob/master/README.md

And I'm using the "Borderless" image gallery as shown on the demo page: https://blueimp.github.io/Bootstrap-Image-Gallery/ 我正在使用演示页面上所示的“无边界”图像库: https : //blueimp.github.io/Bootstrap-Image-Gallery/

I have the thumbnails displaying properly, and clicking on a thumbnail opens the lightbox viewer succesfully. 我的缩略图显示正确,单击缩略图成功打开了灯箱查看器。 I can also navigate through the lightbox slides succesfully. 我也可以成功浏览灯箱幻灯片。 But, I'm trying to figure out how to programmatically open the lightbox viewer. 但是,我试图找出如何以编程方式打开灯箱查看器。 Basically I want to do what the "Launch Image Gallery" button does on the demo site, but do it on page load (document ready) rather than with a button click. 基本上,我想在演示站点上执行“启动图片库”按钮的操作,但是要在页面加载(准备好文档)时执行此操作,而不是单击按钮。 I found that the demo site attaches the following jquery to the "Launch Image Gallery" button: 我发现演示站点将以下jquery附加到“启动图片库”按钮:

$('#image-gallery-button').on('click', function (event) {
  event.preventDefault();
  blueimp.Gallery($('#links a'), $('#blueimp-gallery').data());
});

So I tried on my site: 所以我尝试在我的网站上:

$(document).ready(function(){
  blueimp.Gallery($('#links a'), $('#blueimp-gallery').data());
});

And that does cause a lightbox to load, but only the first image in the set actually displays, and trying to navigate to the next image shows a console error: 确实会导致载入灯箱,但是实际上只显示集合中的第一个图像,尝试导航到下一个图像会显示控制台错误:

Uncaught TypeError: Cannot read property 'style' of undefined

I've been going through the docs for a while now trying various things but can't seem to programmatically trigger a lightbox gallery that works properly. 我已经尝试了一段时间的文档,现在尝试各种操作,但是似乎无法以编程方式触发可以正常工作的灯箱画廊。 What is the best way to do this here? 最好的方法是在这里做什么?

It's simple. 这很简单。 Try this: 尝试这个:

$(document).ready(function(){
  $('#links a:first').trigger('click');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM