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

前端 未结 5 2209
春和景丽
春和景丽 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:50

    Ok, I think I have the answer to your problem (and mine!).

    If you're installing the versions hosted on github, you're probably installing the "vanilla" version, not the jquery plugin. That's what you'll be doing if you install via bower, for example, which is what I was doing.

    Here's what I found with a search on bower:

    % bower search masonry
    # jquery-masonry git://github.com/desandro/masonry
    # masonry git://github.com/desandro/masonry.git
    # $.masonry git://github.com/tysoncadenhead/masonry
    # angular-masonry git://github.com/passy/angular-masonry.git
    # jquery.masonry git://github.com/tysoncadenhead/masonry.git
    

    AFAICT, jquery-masonry, $.masonry and jquery.masonry are all pointing to the same source (in two different locations), and it's not the jquery plugin it's just the "vanilla" version of masonry.

    Instead, just download from here and extract the file jquery.masonry.js, but it in your assets path, and add a shim for it with a dependency on jquery.

    After you do all that, it should work. Of course since it's not installed through bower, you can't manage dependencies as you would with other bower packages. I honestly don't understand what's going on but it looks like a problem on the package-maintainer's side.

    Hope that helps.

    UPDATE: Although the above works, note that the version downloaded from meta.metafizzy.co is quite old and depends on an outdated version of jquery. I think I'm just going to go with the vanilla version, it seems that the plugin is not being maintained.

提交回复
热议问题