Javascript 使用imagesLoaded,但获取错误imagesLoaded不是一个函数 我所做的 包括文档提供的CDN脚本标记 围绕使用同位素初始化我的网格包装imagesLoaded函数 更改了默认的#容器,以匹配我的父容器,即。礼品 在myscripts.js

Javascript 使用imagesLoaded,但获取错误imagesLoaded不是一个函数 我所做的 包括文档提供的CDN脚本标记 围绕使用同位素初始化我的网格包装imagesLoaded函数 更改了默认的#容器,以匹配我的父容器,即。礼品 在myscripts.js,javascript,jquery,function,jquery-isotope,Javascript,Jquery,Function,Jquery Isotope,使用imagesLoaded,但获取错误imagesLoaded不是一个函数 我所做的 包括文档提供的CDN脚本标记 围绕使用同位素初始化我的网格包装imagesLoaded函数 更改了默认的#容器,以匹配我的父容器,即。礼品 在myscripts.js中的动态内容之后初始化 在过去,我还尝试在初始化网格后使用iso.layout() 客观的 .gift元素不应相互重叠 scripts.js index.html 您是否在script.js之前请求imagesloaded.j

使用imagesLoaded,但获取错误imagesLoaded不是一个函数 我所做的
  • 包括文档提供的CDN脚本标记
  • 围绕使用同位素初始化我的网格包装imagesLoaded函数
  • 更改了默认的
    #容器
    ,以匹配我的父容器,即
    。礼品
  • 在my
    scripts.js中的动态内容之后初始化
  • 在过去,我还尝试在初始化网格后使用
    iso.layout()
客观的
  • .gift
    元素不应相互重叠
scripts.js index.html


您是否在script.js之前请求imagesloaded.js?@mjwatts是的,这是一个问题吗?您是否尝试将您的javascript添加到一个onload事件?@mjwatts全部或部分?如果您在script.js之前请求imagesloaded.js,查看您的建议片段会有所帮助?@mjwatts是的,这是一个问题吗?您是否尝试过将javascript添加到onload事件中?@mjwatts全部或部分?查看您的建议片段会有所帮助
// Dynamically loaded content
// Show all gifts
var giftsContainer = $("#posts-container");
var giftTemplate = $("#post-template").html();

gifts.forEach(function(gift) {
    var templateItem = $(giftTemplate);

    // Replace text with data from spreadsheet
    templateItem.find(".gift__image").attr("src", gift.ImageURL);
    templateItem.find(".gift__name").text(gift.Name);
    templateItem.find(".gift__price").text("$"+gift.Price);
    templateItem.find(".gift__description").text(gift.Description);

    // Add data attributes for sorting, cannot be place onto .gift
    templateItem.addClass(gift.CategoryFixed);
    templateItem.addClass(gift.Type);

    giftsContainer.append(templateItem);

    // Removes Amazon link for those that don't have one
    if (gift.URL !== "amazon.com") {
        templateItem.find(".btn--buy").css("display", "none");
    }

    if (gift.Price === "-") {
        templateItem.find(".gift__price").css("display", "none");
    }
});


$('.gifts').imagesLoaded( function() {
    var $grid = $('.gifts').isotope({
        itemSelector: '.gift',
        layoutMode: 'masonry',
        getSortData: {
            name: '.gift__name',
            price: '.gift__price',
        }
    });
});
        <!-- Gift -->
        <div class="gift" data-id="">
            <!-- <a href="https://www.pinterest.com/pin/create/button/" data-pin-hover="true"></a> -->
            <img src="" data-original="" class="gift__image lazy">

            <p class="gift__name"></p>
            <p class="gift__price"></p>

            <p class=""><span class="gift__description"></span> <a href="" class="gift__link"></a></p>

            <p class="gift__category"></p>
            <p class="gift__type"></p>

<!--            <div class="group--share">
                <div class="gift__share">
                    <div class="gift__icons">
                        <a href="" class="link--twitter" target="_blank"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                        <a href="" class="link--facebook gift-facebook" target="_blank"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                        <a href="" class="link--pinterest" target="_blank"><i class="fa fa-pinterest-p" aria-hidden="true"></i></a>
                        <a href="" target="_blank"><i class="fa fa-envelope" aria-hidden="true"></i></a>
                    </div>
                </div> -->
                <a href="" target="_blank"><button class="btn btn--buy">Buy on Amazon</button></a>
            </div>
        </div> <!-- .gift -->