0

我正在尝试在 Instafeed.js 图像上设置 jQuery Colorbox。这两个脚本分别工作正常,但每当我尝试将颜色框类设置为 Instafeed.js 模板部分中的元素时,颜色框不再工作。

但是,Colorbox 在 Instafeed 脚本之外正常工作,无论是 Colorbox 类设置为 an<a>还是<img>

Instafeed

var userFeed = new Instafeed({
      get: 'user',
      userId: ,
      limit: 20,
      accessToken: '',
      resolution: 'standard_resolution',
      template: '<a href="{{model.images.standard_resolution.url}}" class="box"><img src="{{image}}" /></a>',
    });
    userFeed.run();

彩盒

$(document).ready(function(){
            $(".box").colorbox({transition:"fade"});
        });

这里有同样的问题:https ://github.com/stevenschobert/instafeed.js/issues/198但给出的解决方案由于某些原因不起作用。使用此解决方案,当我单击图像时没有任何反应。使用帖子中显示的我之前的代码,它在不同的窗口中打开了图像。

将 Colorbox 设置为 Instafeed 是否有特定的操作?我已经尽我所能,网上没有太多关于它的内容。

4

1 回答 1

3

我假设您的问题是您在将$(".box")这些元素实际添加到 DOM 之前进行查询。在 Instafeed 将锚元素的标记添加到 DOM 后,您需要分配 Colorbox。

查看Instafeed 的 API,他们为after这类事情提供了回调。这应该有效:

var userFeed = new Instafeed({
      get: 'user',
      userId: ,
      limit: 20,
      accessToken: '',
      resolution: 'standard_resolution',
      template: '<a href="{{model.images.standard_resolution.url}}" class="box"><img src="{{image}}" /></a>',
      after: function(){
          $(".box").colorbox({transition:"fade"});
      },
    });
    userFeed.run();
于 2015-12-22T18:30:12.703 回答