【问题标题】:Instafeed.js and jQuery colorboxInstafeed.js 和 jQuery 颜色框
【发布时间】:2015-12-23 02:30:12
【问题描述】:

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

但是,Colorbox 在 Instafeed 脚本之外正常工作,无论是 Colorbox 类设置为 <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 是否有特定的操作?我已经尝试了所有我能做的事情,网上并没有太多关于它的内容。

【问题讨论】:

    标签: javascript jquery colorbox instafeedjs


    【解决方案1】:

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

    查看Instafeed's 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();
    

    【讨论】:

    • 确实有效!谢谢你提供的解释,我应该多加注意。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 2013-03-11
    相关资源
    最近更新 更多