requireJS with JQuery, Masonry, & ImagesLoaded: Object [object Object] has no method 'imagesLoaded'

前端 未结 5 2202
春和景丽
春和景丽 2021-02-09 16:19

RequireJS newbie here. Trying to convert some JQuery code I had working fine in the old way to work w/ RequireJS.

Header of my page loads three JS files via script tags

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-09 16:48

    Try this instead:

    require([
    'jquery',
    'jquery.masonry',
    'jquery.imagesloaded',
    ], function($, Masonry, ImagesLoad) {
    
        // The following code worked just fine when I included it in the header of the page as-is
    $(function() {
    
        var $container = $('#container');
        // This doesn't work
        $container.imagesLoaded(function() {
                        // Neither does this
                $('#container').masonry({itemSelector : '.item',});
            });
    
    });
    
    });
    

提交回复
热议问题