最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript callback after instagram embeds have loaded? - Stack Overflow

programmeradmin2浏览0评论

I'm attempting to tile multiple Instagram embeds with Masonry. Problem is the instagram embeds change sizes after loading so the layout leaves gaps.

Is there a callback that i can use when all instagram embeds on the page have loaded? I'm thinking i should trigger masonry again after the Instagram embeds have loaded and resized properly

tried $(document).ajaxStop() didn't work

I'm attempting to tile multiple Instagram embeds with Masonry. Problem is the instagram embeds change sizes after loading so the layout leaves gaps.

Is there a callback that i can use when all instagram embeds on the page have loaded? I'm thinking i should trigger masonry again after the Instagram embeds have loaded and resized properly

tried $(document).ajaxStop() didn't work

Share Improve this question edited May 29, 2015 at 3:42 Jake 1151 gold badge3 silver badges15 bronze badges asked May 22, 2015 at 8:42 George Ananda EmanGeorge Ananda Eman 3,3528 gold badges30 silver badges30 bronze badges 6
  • why don't you load it first from instagram then render the Masonry? – aswzen Commented May 25, 2015 at 7:24
  • Are you hard-coding those embeds? Do they obey any rule of choosing (last pics of some hashtag, last pics of specific user)? It sounds to me that you should make a request to the Instagram API, get all the photos at the same time and create your own html with the response (json). But this method depends on how are you selecting the photos. – Léo Muniz Commented May 26, 2015 at 0:41
  • @aswzen yes that's exactly what i'm trying to do, care to elaborate on how to achieve that? What happens now is when the page loads the instagram embeds are loaded partially (in text form), and then iam assuming it makes ajax calls to load the image and stylesheets for the iframe. I need a way to know that the embeds have finished loading properly so i can trigger masonry – George Ananda Eman Commented May 26, 2015 at 3:11
  • @LéoMuniz I'm currently embedding by copying the embed code into a new post (via the wordpress TinyMCE editor on the text tab), i have several of these each as a separate post – George Ananda Eman Commented May 26, 2015 at 3:12
  • I've deleted my answer because i miss understand the question. – ecarrizo Commented May 28, 2015 at 17:26
 |  Show 1 more ment

2 Answers 2

Reset to default 6

I had an issue dealing with resizing due to AJAX requests when I was using the Twitter Javascript Embed code. I resolved this by using the following code:

$('#div').bind("DOMSubtreeModified", function() {
    // ...
});

This code will execute when elements are modified under a div element with an id of div. This was very useful. If you need more assistance, don't be afraid to ment on this answer.

There's a solution by Daniel Buchner you can use to detect (event callback) element resize. You can wrap each embed in an element (<div>) and attach the resize listener to your div. Whenever there's a resize, trigger Masonry. If that bees over saturated with rearrange triggers, set a timeout (500ms) when the resize event occurs to only rearrange after a stable period.

The resize listener is available here.

发布评论

评论列表(0)

  1. 暂无评论