简体   繁体   English

如何将imagesLoaded.js与jribbble.js和masonry.js结合使用

[英]How to use imagesLoaded.js in conjunction with jribbble.js and masonry.js

I have set up Masonry ( http://masonry.desandro.com/ ) to display a grid of content that includes text and images. 我已经设置了Masonry( http://masonry.desandro.com/ ),以显示包含文本和图像的内容网格。

Some of the images are shots from Dribble that are being fetched from the Dribbble API by way of the jribbble jquery plugin ( http://lab.tylergaw.com/jribbble/ ) 一些图像是来自Dribble的照片,这些图像是通过jribbble jquery插件( http://lab.tylergaw.com/jribbble/ )从Dribbble API获取的。

I need to use imagesLoaded ( http://desandro.github.io/imagesloaded/ ) to detect when the Dribbble images are loaded and then layout Masonry again after all images have loaded to avoid overlapping grid items that are caused by images that change size after the initial Masonry layout. 我需要使用imagesLoaded( http://desandro.github.io/imagesloaded/ )检测何时加载了Dribbble图像,然后在所有图像加载完毕后再次进行砌筑,以避免由尺寸改变的图像引起的重叠网格项在最初的砌体布局之后。

The problem: Masonry is not laying itself out again after the Jribbble images load leaving the masonry grid with overlapping images. 问题是:在加载Jribbble图像后,砌体不会再次布置自身,从而使砌体网格中出现重叠的图像。

I have imported Jquery, imagesLoaded, Masonry and Jribbble in that order. 我已经按顺序导入了Jquery,imagesLoaded,Masonry和Jribbble。 Here is my Jquery that I am importing after the plugins: 这是我在插件之后导入的Jquery:

$(document).ready(function() {

/*------------------------------------*\
    Jribbble
\*------------------------------------*/
    $.jribbble.getShotsByPlayerId('88paulmurphy', function (playerShots) {

        var dribbbles = [];

        $.each(playerShots.shots, function (i, shot) {
            dribbbles.push('<a href="' + shot.url + '"><img src="' + shot.image_url + '" alt="' + shot.title + '" class="img--center"></a><header><h2>' + shot.title + '</h2><ul class="widget__tag-list"><li><span class="tag tag--dribbble"> Dribbble Shot</span></li></ul></header><footer class="widget__footer"><a href="' + shot.url + '" class="btn">View on Dribbble</a></footer>');
        });

        $('.js-dribbble').each(function(index){
            this.innerHTML = dribbbles[index];
        });

    }, {per_page: 6});


/*------------------------------------*\
    Masonry
\*------------------------------------*/
    var $container = $('.main').masonry();
    // layout Masonry again after all images have loaded
    $container.imagesLoaded( function() {
        $container.masonry({
            itemSelector: '.widget',
            transitionDuration: '0.4s'
        });
    });
});

Any help would be great, thanks! 任何帮助将是巨大的,谢谢!

Use the jribbble Callback function to load the masonry grid once the data is loaded. 数据加载后,使用jribbble回调函数加载砌体网格。 This is very simple but it works for me: 这很简单,但对我有用:

// Create function to prepare masonry grid //创建函数以准备砌体网格

function loadGrid() { masonry.... }

// Create function for jribbble to load the data on callback, then run your loadGrid masonry function //为jribbble创建函数以在回调中加载数据,然后运行您的loadGrid石工函数

var callback = function (listDetails) {  load dribbble shots into object & call the masonry grid function }

// Call jribbble //调用抖动

    $.jribbble.getShotsByPlayerId(playername, callback, {page: 1, per_page: 15})                                                                                                                         

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

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