首页 > 解决方案 > nanogallery2:单击缩略图时是否可以转到链接而不是打开灯箱

问题描述

我正在使用 [nanogallery2][1]。我将一些项目动态添加到我的画廊(通过使用此示例:https ://codepen.io/Kris-B/pen/wJKowg )。我知道通过设置该选项thumbnailOpenImage: false,我们可以在单击缩略图时禁用显示灯箱。是否可以为图库中的项目设置链接,以便在用户触摸缩略图时将其发送到该链接?

标签: javascriptgallerynanogallery

解决方案


您可以使用属性定义自定义 URL destinationURL

从上面提到的 Codepen,这里有一个例子:

  ...
  // create the new item
  var ID = ngy2data.items.length + 1;
  var albumID = '0';
  var newItem = NGY2Item.New(instance, 'new berlin ' + ID, '', ID, albumID, 'image', '' );

  // define thumbnail -> image displayed in the gallery
  newItem.thumbSet( baseURL + 'berlin2t.jpg', 135, 204); // w,h

  // define URL of the media to display in lightbox
  newItem.setMediaURL( baseURL + 'berlin2.jpg', 'img');

  // DEFINE YOUR SPECIFIC URL
  newItem.destinationURL = "[CUSTOM_URL]";

  ...

无需禁用该thumbnailOpenImage选项。


替代解决方案:

使用fnThumbnailOpen回调。

这是一个示例,显示如何用 Fancybox 替换内部灯箱:https ://codepen.io/Kris-B/pen/zZNMJj


推荐阅读