简体   繁体   English

Fancybox图片库不起作用

[英]Fancybox image gallery doesn't work

I'm trying to do a Fancybox image gallery. 我正在尝试制作Fancybox图片库。 I have a function that takes a list of image URLs and appends them to the DOM like so 我有一个函数,它接收图像URL的列表并将其附加到DOM,就像这样

function handleImageURLs(imageURLs) {
  var appendString = "";

  //Create an <a> tag for each image URL
  for(var i = imageURLs.length - 1; i >= 0; i --) {
    appendString += "<a href='"+ imageURLs[i] +"' rel='img_preview'><img src='"+ imageURLs[i] +" />'</a>";
  }

  //Add the <a> tags containing images to the <body> element
  $("body").append(appendString);

  //Select the image <a> tags and call Fancybox
  $("a[rel='img_preview']").fancybox({
    onCleanup: function() {
      //do cleanup stuff, remove images, etc.
    }
  });
}

Everything works fine. 一切正常。 The <a> tags get added to the DOM. <a>标记被添加到DOM中。 But Fancybox doesn't open at all. 但是Fancybox根本没有打开。 And doesn't throw any errors. 而且不会抛出任何错误。 Any idea what I'm doing wrong? 知道我在做什么错吗?

结合使用这两种方法,并在我要显示的图像上触发了click事件。

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

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